aspose file tools*
The moose likes Java in General and the fly likes how to read line by line and pass each line value to a method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to read line by line and pass each line value to a method " Watch "how to read line by line and pass each line value to a method " New topic
Author

how to read line by line and pass each line value to a method

uma prem
Greenhorn

Joined: Jun 21, 2010
Posts: 11
hi,

i have a text file, having one value in each line digitsandnumbers. now once i read it line by line i need to pass each lines value to one staticmethod (class ABC)which takes it as one of the parameter to get me one more id. Please help me,.i am in trouble.... Please help me with the correct code

what i have done so far is

thanks a lot for your time
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3165
    
  10
TellTheDetails


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
I don't understand the problem. You obviously know how to write a method, so what you want is a method which takes the line and extracts the UUID from it. Your code already gives you half the methodObviously I don't know how to complete your method for you.

Why are you making all your methods static? Please put spaces before and after binary operators, after commas etc. Your code is hard to read as it stands.
uma prem
Greenhorn

Joined: Jun 21, 2010
Posts: 11
Hi Campbell,

Thanks for your reply,

My problem is :

My bidfilename is bid.txt having one value in each line(1000lines together)
Now in my program, I am passing the entire textfile(bid.txt) to the method, instead of one line at a time.I want help in that

fieldname="+@\\:Identifier:\""+text+"\"";
uuid=ABC.GetUIDByField(pathname,fieldname);//

like when I check in the fieldname parameter inside the method GetUIDbyField of class ABC,the fieldname shows +@\\:Identifier:\""+bid.txt(the entire filename) ,instead of +@\\:Identifier:\""+12134(one by one line value at a time)

hope i am clear of the problem facing

Please reply
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 198

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Still don't understand the problem. What are you doing in that getUID method?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Sai Hegde wrote:

http://www.coderanch.com/how-to/java/AvailableDoesntDoWhatYouThinkItDoes

For files it's usually pretty accurate but that still doesn't guarantee that it works. If your disk is really busy then available() may return 0 even if there's still data available.

A BufferedReader wrapped around a FileReader seems like a better solution. The Javadoc of DataInputStream's readLine() method also suggests using BufferedReader for reading lines.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 198

Nice, Rob! That is a valuable insight. Thanks!
@Campbell
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to read line by line and pass each line value to a method
 
Similar Threads
Tokenizing a line and searching
Why notify is throwing an exception here ?
read content of text file which is in jar
How do I read and write text files with different character sets?
Help with ArrayList error