我试图读取这样的.txt文件:
@Override annotation informs the compiler that the element is meant to
override an element declared in a superclasses.
// mark method as a superclass method
// that has been overridden
@Override
int overriddenMethod() { }
我的问题是,如果我使用一个简单的字符串,我可以这样做,它显示的完全如上所示,还是必须是一个字符串数组?
答案 0 :(得分:0)
是的,您可以使用\ Z分隔符读取单个字符串,直到读取EOF字符,java使用一些scape sequences来显示空格,斜杠等。
String content;
try{
content = new Scanner(new File("file.txt")).useDelimiter("\\Z").next();
} catch(FileNotFoundException e){
System.out.println("file.txt not found");
}