Solved

Java program to read a text file

Posted on 2010-11-30
10
278 Views
Last Modified: 2012-08-14
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
Comment
Question by:dshrenik
10 Comments
 
LVL 12

Expert Comment

by:enachemc
ID: 34236849
you need to use locks
synchonized is used for concurrent acces of threads in the Java Virtual Machine
0
 

Author Comment

by:dshrenik
ID: 34236850
If possible, can u give some sample code? Thanks!
0
 
LVL 20

Expert Comment

by:a_b
ID: 34236866
0
Independent Software Vendors: 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!

 
LVL 92

Expert Comment

by:objects
ID: 34236868
0
 

Author Comment

by:dshrenik
ID: 34236876
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
 
LVL 92

Expert Comment

by:objects
ID: 34236927
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
 

Author Comment

by:dshrenik
ID: 34236940
Suppose I dont use Locks, will I get any errors, or it is just that I wont get the latest values?
0
 
LVL 92

Expert Comment

by:objects
ID: 34236970
generally when you read it you'll whatever the file contains at that point.
depends a bit on the OS though

0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 34236976
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 34237511
A file lock probably won't work. Try using a lock file - it will be portable across your different platforms
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JavaFX TableView not displaying correctly 3 103
ejb mdb examples 1 19
Is there a simpler dropbox system? 10 44
Running JavaFX on the Raspberry Pi 27 120
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question