PrivateFileDialog OpenFileDialog =NewFileDialog ( This, "Open File", filedialog.load);Else if(EventSource = =openFile) {openfiledialog.show (); FileName= Openfiledialog.getdirectory () +Openfiledialog.getfile (); if(FileName! =NULL) ReadFile (fileName); } Publicvoid ReadFile (String fileName) {File file=NewFile (fileName); FileReader Readin=Newfilereader (file);intSize = (int) file.length ();intCharsread = 0;Char[] content =New Char[size]; while(Readin.ready ()) Charsread+ = Readin.read (content, charsread, size-charsread); Readin.close (); Textarea.settext (NewString (content, 0, Charsread));}
Basic steps: Create an object of type FileDialog with parameter this,string,filedialog.load
In the Actionperformed method, if the event source is OpenFile, the File List dialog box is displayed, and the full file pathname is obtained using the GetPath () and GetFile () methods
Override the ReadFile function to define the file and FileReader objects, the Int type object representing the length of the files, and the array of char types
Finally close the FileReader object
Select a file in the file list and display the contents of a file in textarea