سؤال

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