Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a text file with an applet

Status
Not open for further replies.

Mike617

IS-IT--Management
Aug 2, 2009
2
PH
I have a text file that I want my applet to simply be able to read. It's basically a table of contents/search index for a client-side search engine. It's for a bunch of documents that I want to distribute on a CD (therefore, without the use of a server).

My question is: Is there a way to include the text file in a JAR or other kind of archive that would allow my applet to read the file without having a certificate or permissions?

If you have an answer to that, or if you have another suggestion on how to achieve the same result, please let me know. Thanks very much.

Thanks again.
 
Hi!

You can read any text file from that server where the applet was downloaded, thus you do not need to place that file into the jar (but you can do it).

Here is a little example, reads the textfile.txt, and every line in it place a Vector:

private final void loadFileNames() {
String s;
DataInputStream ds;
Vector fns;

fns=new Vector(50);
try {
ds=new DataInputStream(new URL(getCodeBase(), "textfile.txt").openStream());
while (true) {
try { s=ds.readLine(); }
catch (IOException e) { s=null; }
if (s==null) break;
fns.addElement(s);
}
ds.close();
}
catch (Exception e) {}
}

Good luck. Bye, Otto.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top