Solved

Java program to read a text file

Posted on 2010-11-30
10
265 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Options in Zimbra Server 2 54
MySqlDump not dumping triggers 1 31
hibernate example for saving data 19 40
How to convert from xls to xlsx using java 7 39
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

773 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