text file accessing in Applet

V

vidhi

i have an applet application which runns by useing values avilable in a
text file, as per the situation it rung great.
but the problem occures when multiple instance of applet over a network
is running and try to access the text file at same instance, in this
situation only one applet can have access the file and rest are hang up
at line which uses the file, one the applet file which have file access
grant will close then next but only one at this time also get the
access to that file.
i thought i might be sharing vocation problem.
here is the code what i use to access.

BufferedReader br=new BufferedReader(new
InputStreamReader(getClass().getResourceAsStream("MyTextFile.txt")));
try
{
while((str=br.readLine())!= null)
{
strRange=br.readLine();
}
}catch(IOException io){}
 
M

Matt Humphrey

vidhi said:
i have an applet application which runns by useing values avilable in a
text file, as per the situation it rung great.
but the problem occures when multiple instance of applet over a network
is running and try to access the text file at same instance, in this
situation only one applet can have access the file and rest are hang up
at line which uses the file, one the applet file which have file access
grant will close then next but only one at this time also get the
access to that file.
i thought i might be sharing vocation problem.
here is the code what i use to access.

BufferedReader br=new BufferedReader(new
InputStreamReader(getClass().getResourceAsStream("MyTextFile.txt")));
try
{
while((str=br.readLine())!= null)
{
strRange=br.readLine();
}
}catch(IOException io){}

It is up to the operating system (not java) to determine what happens when
the same file is opened multiple times, although usually multiple readers is
ok. Your code shows only file reading but it has some twists that make me
want to ask some questions.

1) When you say it runs great, does that mean the applet can read the file
when the applet and file (server) are on different machines?
2) When you say "and rest are hang up at line" do you mean they throw an
exception and if so what is the exception they throw?
3) Don't make empty exception handlers--print any exception. Is there one
and what does it say?
4 Are you closing the file properly?
5) Is the file really being accessed via the classloader resource stream and
is in the jar file / classpath or is it supposed to be on the local machine?
6) Do you (or does any other code) attempt to write to the file?


Cheers,
Matt Humphrey (e-mail address removed) http://www.iviz.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top