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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

File Systems II<br />

Receive our newsletter with new tips! Almost 6,000 subscribers (by June 2001) can not be wrong!<br />

They read our tips every week! To subscribe to The <strong>Java</strong> FAQ Daily send empty e-mail to:<br />

javafaq-tips-subscribe@topica.com or visit at:<br />

http://www.topica.com/lists/javafaq-tips/<br />

File Systems II<br />

Q: How do I delete a file in <strong>Java</strong>? I have programmed a <strong>Java</strong> application that<br />

needs to delete a file, but I couldn't find anything on the topic.<br />

Answer: in java.io.File there is delete<br />

public boolean delete()<br />

Deletes the file or directory denoted by this abstract pathname. If this pathname<br />

denotes a directory, then the directory must be empty in order to be deleted. Create<br />

a new File object representing the file, and then use the delete () method. If you use<br />

the Microsoft JVM, make sure the file is not shared before you delete it, otherwise<br />

that will not work (the delete () method returns "false").<br />

Q: I need to read C:\test.doc for example and store it somewhere for my future<br />

use. I don't know anything about security. Part 1<br />

Answer: If you want to read a file on the local file system in an applet, you are going<br />

to digitally sign the applet, and the user of the applet is going to indicate trust in the<br />

signature. How you go about this depends on a number of questions, like:<br />

In which browser(s) will the users be running the applet?<br />

Will a <strong>Java</strong> plug-in be installed in the browser?<br />

Can the user install a plug-in?<br />

Here are a few tips on some of the sticky points of signing applets...<br />

-------------------------------------------------------------------<br />

If you are using the jar signing tools that come with the JDK, you'll find that they will<br />

only work with the <strong>Java</strong> plug-in. Netscape and Microsoft IE don't salute the Sun way<br />

of signing applets.<br />

file:///F|/350_t/350_tips/filesystems-II.htm (1 of 4) [2002-02-27 21:17:59]<br />

Visit us here and you will find<br />

much more tips!

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

Saved successfully!

Ooh no, something went wrong!