문제

I have a file whose content as follows:

Testing this program
This is the second line
"This is the Blank line"(Empty line)

This is first line that needs to read and stored
This is the second line that needs to read and stored

So as soon as Blank line is found, I need to start storing the data after the Blank line is detected.

I am using bufferreader and while loop to read line by line.

Any help would be appreciated.

Thanks

            FileReader inputFile = new FileReader(httpPost);
        BufferedReader bufferReader = new BufferedReader(inputFile);

        while ((line = bufferReader.readLine()) != null) 
        {
                if(line.trim().equals(""))
                {
                    //Read file after blank line is detected
                    modifieddata = modifieddata + "\n" + line;
                }
        }       
도움이 되었습니까?

해결책

Am not sure i completely understand what you're trying to achieve, but you are probably trying to do this :

 while ((line = bufferReader.readLine()) != null) 
 {  
      bufferdata+=  System.getProperty("line.separator") + line; 
      if(startSaving)
      {
           modifieddata += System.getProperty("line.separator") + line;
      }
      else  
      {
          originaldata += System.getProperty("line.separator") + line;
      }

      if(line.isEmpty())
      {
           startSaving = true; 
      }
  }

  if(modifieddata.isEmpty())
  {
      modifieddata = originaldata.trim();
  }
  else
  {
      modifieddata = modifieddata.trim();
  }

  String[] array = new String[]{modifieddata, originaldata};

  //Close the buffer reader
  bufferReader.close();

  // return array;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top