Java Code:
import java.io.File; import java.io.FileReader; import java.io.IOException; import javax.swing.JFileChooser; class MyCustomFilter extends javax.swing.filechooser.FileFilter { public boolean accept(File file){ return file.isDirectory()|| file.getAbsolutePath().endsWith(".txt"); } @Override public String getDescription() { return "Video File (*.txt)"; } } private void MenuItem1ActionPerformed(java.awt.event.ActionEvent evt) { // [Find More Java Codes at www.sumikuma.tk] int returnVal = fileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION){ File file = fileChooser.getSelectedFile(); try { textarea.read(new FileReader(file.getAbsolutePath()),null); } catch (IOException ex) { System.out.println("problem accessing file"+ file.getAbsolutePath()); } }else { System.out.println("File access cancelled by user."); } } private void ExitActionPerformed(java.awt.event.ActionEvent evt) { // Find More Java Codes at www.sumikuma.tk System.exit(0); } [Find More Java Codes at www.sumikuma.tk]
You can also download text file of this code here: TxtViewer.txt
Comments
Post a Comment