Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

Java program to read a text file

Please give me the code that reads a text file.
The important thing is that the file could be modified by another program (Python) while the Java program tries to read it. Do I need to use locks? Or is it enough if I use a synchronized function?
0
dshrenik
Asked:
dshrenik
2 Solutions
 
enachemcCommented:
you need to use locks
synchonized is used for concurrent acces of threads in the Java Virtual Machine
0
 
dshrenikAuthor Commented:
If possible, can u give some sample code? Thanks!
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
dshrenikAuthor Commented:
So both my Python program and Java program need to use locks?
If yes, will they recognize the locks set by the other program?
0
 
objectsCommented:
you need to use a method that both understand

you can try FileLock, but it is platform dependant
http://www.exampledepot.com/egs/java.nio/SetFileLock.html

0
 
dshrenikAuthor Commented:
Suppose I dont use Locks, will I get any errors, or it is just that I wont get the latest values?
0
 
objectsCommented:
generally when you read it you'll whatever the file contains at that point.
depends a bit on the OS though

0
 
objectsCommented:
0
 
CEHJCommented:
A file lock probably won't work. Try using a lock file - it will be portable across your different platforms
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now