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 />

also believe it is possible to grant privileges to a codebase in Netscape without<br />

signing. This is done by editing the 'prefs.js' file on the client. Obviously, this is not<br />

possible on the internet, but, for an intranet environment, this could be a solution.<br />

Anyway, when an applet tries to enable a privilege, the Netscape browser will pop up<br />

a window asking the user if they wish to grant the privilege. This decision can be<br />

persistent.<br />

The user can manage the privileges they have granted by clicking on the padlock<br />

icon in the bottom left corner of their browser window, and selecting the<br />

"<strong>Java</strong>/<strong>Java</strong>Script" section.<br />

If your users may be using Microsoft IE as well as Netscape, you'll have to learn the<br />

Microsoft security API. I haven't done this yet, but I believe it is possible to code an<br />

applet so that it will work in either browser.<br />

Another alternative is to code different versions of the applet, and build the page<br />

containing the applet dynamically, based on the "User-Agent". I have found that it is<br />

possible in IE to grant universal privileges to an applet, even if it is not signed, but I<br />

sure wouldn't recommend doing that.<br />

--<br />

Joe Morrogh - Excite@Home - The Leader in Broadband http://home.com/faster<br />

Q: Is there any method like writeLine()?<br />

Answer: For writing text to files, you can use a FileWriter; for binary data, use a<br />

FileOutputStream. Both are in the java.io package. Have a look in the docs, all you<br />

need is there. Oh, you might want to wrap your writer/outputstream in a buffered one<br />

for more efficiency. Something like this:<br />

FileWriter fw = new FileWriter("D:\temp\test.txt");<br />

BufferedWriter bw = new BufferedWriter(fw);<br />

bw.write("Some text on the first line");<br />

bw.newLine(); // have the Writer insert the newline<br />

bw.write("Some more text, followed by an explicit newline\n");<br />

bw.close();<br />

Note, that while \n will probably work, newLine() inserts the platform's own<br />

line separator (ie, \r on Mac, \r\n on Windows, \n on *nix).<br />

--<br />

Michiel<br />

Q: I want to copy a set of gif files from one directory to another. If I use any of the<br />

File Reader/Write classes of java.io.package, gif files are being copied but are<br />

distorted.<br />

Most probably because <strong>Java</strong> reads in character mode. So, how can I copy gifs ?<br />

Answer: use FileInputStream FileOutputStream instead.<br />

Q: Is there a newsgroup on how to use <strong>Java</strong> for CDs? I mean not CD that install<br />

someting but CDs that you browse.<br />

Answer: Strictly speaking, there is no difference between "CDs that install<br />

something" and "CDs that you browse". All CDs contain the same file structure. It's<br />

up to the operating system to decide what it does with those files. Windows includes<br />

functionality to start a special file on the CD automatically, typically to install<br />

something.<br />

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

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

Saved successfully!

Ooh no, something went wrong!