Solved

Java program to read a text file

Posted on 2010-11-30
10
257 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JAVA part two 5 56
Java passing arguments (type error) 2 47
ArrayIndexOutOfBoundException 9 66
Windows 10 IE Certificate Issue 10 41
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

932 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now