Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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