• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

issue with files reading and processing

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 22446
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic