By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,653 Members | 1,483 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,653 IT Pros & Developers. It's quick & easy.

Uploading file in java

P: 12
Hi there,can anyone tell me how to read multiple lines and store their value.

eg:file.txt

Probable Cause: The network operator has issued an alter attribute command for
the specified LCONF assign. The old value and the new value are show
Action Taken : The assign value is changed from the old value to the new
value. Receipt of this message does not guarantee that the new attribute
value was accepted by clients who use it. Additional messages may be.

Probable Cause: The network operator has issued an info attribute command for
the specified LCONF assign. The default value being used is displaye
Action Taken : None. Informational use only.

In above file,Probable Cause and Action Taken are the column of database table.And after Probable Cause: those are the value to be stored in the database table for probable cause column,same goes with action taken.

so how can i read the multiple lines and store their value.I have to read the value for probable cause until the line comes with Action Taken.I'm using bufferedReader and readLine() function read one line at a time.So can anyone tell me how to read directly from probable cause to action taken no matter how many line comes between them.

With regards
Biraj
Mar 20 '12 #1
Share this Question
Share on Google+
4 Replies


10K+
P: 13,264
If the value part will never contain a colon then read the value into a string until you encounter a line with a colon and don't include that line with the colon.
You can split the column name from the value part using String.split(":");
Mar 20 '12 #2

P: 12
thanks for the answer.Can you provide me the code to read till colon appears.
Mar 20 '12 #3

10K+
P: 13,264
In your while loop when you read the line using
String line = br.readLine();
You check for : using if(line.contains("Probable Cause:")) { ...

You then separate the cause label from the cause text using line.split(":")
Mar 20 '12 #4

P: 12
Thanks again that worked.
Mar 20 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.