Solved

Java program to read a text file

Posted on 2010-11-30
10
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

636 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