aspose file tools*
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
Author

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
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

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
Greenhorn

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();
fchannel.lock();
fin.write(250);
fchannel.force(false);
Thread.sleep(200000);
} catch(Exception e) {
e.printStackTrace();
}

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 nio.channel packages.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: issue with files reading and processing