• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Use plain text files

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to convert my command line app to an applet. My command line app uses plain text files to load some data that program needs. When I implement this class in an applet it can't read the file (eventhough it's in the same directory). I use this principle to load files:

try{
BufferedReader reader = new BufferedReader(new FileReader(new File("text.txt"));
String line = null;
while((line=reader.readLine()) != null){
System.out.println(line);
}
reader.close();
} catch(Exception ex) {
System.out.println("Cannot read file");
}

What do I need to change?
And are there some visual component which can display my System.out.println("")? I mainly want to make it into an applet to make distribution easier, but the output of the program can still come in some sort of text window (which one?).
[ January 07, 2007: Message edited by: Tim Pintens ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a security precaution, applets are not allowed to perform file I/O. There are two principal ways around that: digitally signing the applet, and aletring the local security policy. Both are outlined here.

The output of System.out goes to the Java Console, which you can open either through a menu in the browser, or through the little Java icon in the Windows tray. On OS X , you'd use Console.app.

But if the program has only text input and output, why make it an applet? Maybe a WebStart application would be more appropriate?
 
Kim Mirtens
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I didn't make myself clear enough: the file it has to load recides on the host. I do not want access to the local filesystem of the user. The program accually uses a textfile as a small database to get data.
For example if I would like to make an applet which gives back the capital of the country when a country is selected out of a list. Can't I just use a textfile which holds comma-separated text to find the capital.

Example of what the textfile would hold:
France,Paris
Germany,Berlin
UK,London

I do not want to put this data directly into the program, because I want it to be dynamically i.e. I want to be able to at capitals without changing the program, but only changing the textfile.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That makes more sense. You can use HTTP to retrieve the file. It could be as simple as



At which point you can use String methods to parse the file contents into its various parts.
[ January 07, 2007: Message edited by: Ulf Dittmer ]
 
In the renaissance, how big were the dinosaurs? Did you have tiny ads?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic