Solved

Java program to read a text file

Posted on 2010-11-30
10
246 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
Comment Utility
you need to use locks
synchonized is used for concurrent acces of threads in the Java Virtual Machine
0
 

Author Comment

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

Expert Comment

by:a_b
Comment Utility
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0
 

Author Comment

by:dshrenik
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 92

Expert Comment

by:objects
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 86

Assisted Solution

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

772 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

10 Experts available now in Live!

Get 1:1 Help Now