Uploading file in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • James Josh
    New Member
    • Mar 2012
    • 12

    Uploading file in java

    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
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    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(": ");

    Comment

    • James Josh
      New Member
      • Mar 2012
      • 12

      #3
      thanks for the answer.Can you provide me the code to read till colon appears.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        In your while loop when you read the line using
        String line = br.readLine();
        You check for : using if(line.contain s("Probable Cause:")) { ...

        You then separate the cause label from the cause text using line.split(":")

        Comment

        • James Josh
          New Member
          • Mar 2012
          • 12

          #5
          Thanks again that worked.

          Comment

          Working...