Sign In. Contact Us. All Rights Reserved. Catalog Java. Open your text editor and type in the following Java statements: The program instantiates a File object and passes to the constructor the directory whose contents are to be displayed.
Replace the directory shown with a directory on your file system that you know contains files and at least one subdirectory. The listFiles method returns an array of File objects. The program iterates through the array and tests each entry. A message is displayed indicating if the object is a file or a directory. This is where the file contents are loaded and displayed. Because the file contents are to be displayed in a TextArea component, the legitimate assumption is that the file contains characters.
Thus, we use a character input stream, a FileReader , instead of the byte input stream used in the FileCopy program of Example Once again, use a finally clause to ensure that the FileReader stream is properly closed. The actionPerformed method handles GUI events. If the user clicks on the Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. Most popular in Java. Most visited in Java Programs.
We use cookies to ensure you have the best browsing experience on our website.
0コメント