1
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class Main {
public static void main(String args[]) throws IOException {
    //Instantiating the File class
    String filePath = "Data.txt";
    //Instantiating the Scanner class to read the file
    Scanner sc = new Scanner(new File(filePath));
    //instantiating the StringBuffer class
    StringBuffer buffer = new StringBuffer();
    //Reading lines of the file and appending them to StringBuffer
    while (sc.hasNextLine()) {
        buffer.append(sc.nextLine()+System.lineSeparator());
    }
    String fileContents = buffer.toString();
    //closing the Scanner object
    sc.close();
    String oldLine = "No_Assessment";
    String newLine = "Yes_Assessment";
    //Replacing the old line with new line
    fileContents = fileContents.replaceAll(oldLine, newLine);
    //instantiating the FileWriter class
    FileWriter writer = new FileWriter(filePath);
    writer.append(fileContents);
    writer.flush();
}
}

Error I get : Cannot resolve method 'lineSeparator' in 'System'. Is that my java version too low or any needed library has to be imported to use lineSeparator. Thx in advance.

Yew
  • 87
  • 5

1 Answers1

1

Which java version are you using? System.lineSeparator() was added in 1.7

NightLight
  • 213
  • 6
  • 12