File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

issue with files reading and processing

 
Rahul Noel
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rahul Noel
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic