I am a beginner in Java. I do not understand the importance of the File class. In the real programming world, why and when would i need to use it? Please provide some business contexts that will help me clear my understanding about the File class.
In the OOPS way of doing things.. we take everything as objects. Similarily to represent a File we have a File object which encapsulates certain attributes of a file and provides behaviour similar pertaining to a file.<br><br>It's an abstract representation of a file.
I have recently used the File class in a program that sorts and catalogs directories. I used it because it allows for the easy retrieval of file properties.<br><br>The first part of the program recursively searches the directory for files and it returns an array of strings. The strings would be of the form "c:\java\test.class" without the quotes. From this you can't get any information about the file's size, date stamp, etc. from there I create the file objects by passing the string array to a method that converts the string array to a File array, something like this:<br><br>public File[] convert(String[] list)<br>{<br> File [] newList = new File[list.length];<br> for(int i = 0; i < list.length; i++)<br> newList<i> = new File(list<i>);<br> return newList;<br>}<br><br>It makes it much easier to output the path, file name and attributes to a text file or database.<br><br>Hope this clears up your problem somewhat....<br><br> <p> fenris<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.