Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading from file

 
meera sood
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
is it possible for my applet to read some data from a flat file?? if yes, could somebody please tell me how to achieve this?
thanks in advance,
Meera
 
Tim Holloway
Saloon Keeper
Posts: 18367
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd have to create a signed applet. Otherwise the Java sandbox will cause a security exception to be thrown when you attempt to open and read the file.
The code to open and read a file is easy and you can test it with the AppletViewer. Signing an applet is a major pain.
 
meera sood
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
but how do i create a signed applet...
anyways, i tried out a piece of code yesterday, and it worked....what i did was, created a URL connection to connect to my file lying on the server.
here is the code for that:

and thus i was able to communicate with my file....
could you please tell me about signed applets also...maybe that code is more efficient....
thanks in advance
Meera
 
Tim Holloway
Saloon Keeper
Posts: 18367
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Efficient" is a dangerous term. To be truly efficient, you don't use Java and you don't run over a network. In the days of 2GHz CPUs and high=speed data lines, the emphasis is more on security, reliability, and productivity.
Although there ARE reasons for having an Internet app access local resources, too often all it really is is people trying to write web apps in the pre-web mode. Trying to make the Internet look like a local PC.
From an enterprise point of view, local files are not such a good thing. If they're stored on a server, the enterprise support people can more easily keep it backed up. It's easier to secure data on a server than on a desktop or laptop. The data is accessible based on who you are instead of what machine you happen to be sitting in front of, and is just as usable from your laptop out in the field as it is in your office (and you don't end up with out-of-date copies). Plus, if your desktop PC dies, the data is still usable - just go to a new PC.
I'm afraid that it's been too long since I looked at signing applets to be able to help. It's not a simple process, since IE and Netscape have different signing mechanisms and I'm not sure which, if either, the Java plug-in uses. Maybe someone else on this forum can help. The docs on the process are at http://java.sun.com
 
Tom McComb
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's too bad people are too busy on their soapboxes to be helpful or even observant. <b>I</b> could tell by your code that you are not trying to hit the local file system, but the server's file system; you're just trying to get data/etc from the server. Well, I tried it and figured it out:
<pre>
URL myUrl = getCodeBase();
try
{
String path = "/myfolder/sample.txt";
URL dataURL = new URL(myUrl.getProtocol(), myUrl.getHost(), myUrl.getPort(), path);
URLConnection dataURLConnection = dataURL.openConnection();
BufferedReader content = new BufferedReader(new InputStreamReader(dataURLConnection.getInputStream()));
for(String inLine = "Reading..."; inLine != null; inLine = content.readLine())
ta.append("\n" + inLine);
}
catch(Exception e)
{
ta.append("\nError in getText: " + e);
}
</pre>
In this case, ta is a TextArea object. It could just as easily be a StringBuffer. Hopefully, you get the concept now.
FWIW, my two euros on the subject.
 
meera sood
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx for your help... yeah i know that i was communicating with the server... see, in my applet, i ahve to communicate with files, both on the server and on the client. i figured this way out to communicate with the server, and now i am trying to do it with the client. I managed to make signed applets, but then the way i made them, the user has to manually import and install the certificate, and frankly, who has the patience these days to do that... i mean i, as an end user, would never go through all those steps... could you please tell me if there is any way that the certificate can be installed at the click of a button..... and my applet thus access the local file system.
thanx a lot.....
( i was not expecting any further replies to my queries )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic