Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在Java中解析lineSeparator_Java - Fatal编程技术网

无法在Java中解析lineSeparator

无法在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;

获取错误:无法解析“系统”中的方法“lineSeparator”。是因为我的java版本太低,或者需要导入任何库才能使用lineSeparator。Thx。您使用的是哪个java版本?
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();
}
}