27.04.2013 Views

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

File Systems I<br />

}<br />

}<br />

myObject = (Object)test;<br />

s.saveMyObject("myfile", myObject);<br />

If you open myfile you will see that this object includes our string "test"<br />

In the same manner you can read this object from file...<br />

Q: Can anyone write me a short method that lets me know what files are in a<br />

particular directory?<br />

For example, I want to know that directory, d:/temp/aaa, has files a.txt, b.java,<br />

b.class.<br />

Also related to this, how do I find out what folders I have?<br />

Thanks in advance.<br />

Answer: use our program as a base and add checking for the files and directories<br />

you need to find!<br />

here it is:<br />

import java.io.File;<br />

public class Save{<br />

public void showDirectoryList() {<br />

File dir = new File("d:/temp/aaa");<br />

File[] list = dir.listFiles();<br />

for (int i=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!