File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes issue with files reading and processing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "issue with files reading and processing" Watch "issue with files reading and processing" New topic

issue with files reading and processing

Rahul Noel
Ranch Hand

Joined: Jul 18, 2008
Posts: 51
I have a two files,it has accid,txtype,amount. one person accid may exist in another file, task is to read contents from files and storing that values(accid,txtype,amount),then number of threads will access this file depending on the txtype like withdraw or deposit the processing should be done.If it is withdraw it has to check with other files data and balance.How can we achieve this

Thanks in Advance.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

Please Use One Thread Per Question. This is basically the same problem as this one.

Considering this thread has more information in it, let's continue here.

How To Ask Questions How To Answer Questions
Martijn Verburg

Joined: Jun 24, 2003
Posts: 3275

You'll want to begin by looking at the io or nio packages in Java (nio is the newer (and better?) way to perform file I/O.

Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Rahul Noel
Ranch Hand

Joined: Jul 18, 2008
Posts: 51
Using I/O only.I am facing difficulty in reading file and separating the strings and storing it in hashMap. please help me.
Rahul Noel
Ranch Hand

Joined: Jul 18, 2008
Posts: 51

Here,my task is to get files data from no. of files and reading it and separate data like accid,txtype,amt and store it in hashMap. I have to synchronize this data in threads I mean many threads will use this data.
vipin jos

Joined: Nov 18, 2008
Posts: 24
I am not sure what you meant by synchronization. Solution as per my understanding is as follows.
If you want to lock the file while a write is in progress, you should be using nio.

try {
File file = new File("a.txt");
FileOutputStream fin = new FileOutputStream(file);
FileChannel fchannel = fin.getChannel();
} catch(Exception e) {

If you run the above code and while it is sleeping, if you try to edit it and save(use textpad or notepad), it would not allow since it is locked by the Thread.

For more information, read through nio and packages.
I agree. Here's the link:
subject: issue with files reading and processing
It's not a secret anymore!