无法在Java中解析lineSeparator
获取错误:无法解析“系统”中的方法“lineSeparator”。是因为我的java版本太低,或者需要导入任何库才能使用lineSeparator。Thx。您使用的是哪个java版本?无法在Java中解析lineSeparator,java,Java,获取错误:无法解析“系统”中的方法“lineSeparator”。是因为我的java版本太低,或者需要导入任何库才能使用lineSeparator。Thx。您使用的是哪个java版本? System.lineSeparator()绝对是在1.7中添加的,谢谢回复!是的,我使用的是1.6版本,这就是我出错的原因。谢谢你的帮助! import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter;
System.lineSeparator()
绝对是在1.7中添加的,谢谢回复!是的,我使用的是1.6版本,这就是我出错的原因。谢谢你的帮助!
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();
}
}