【发布时间】:2021-12-04 23:50:27
【问题描述】:
我有这段代码可以读取文件并将内容作为字符串返回,但我不知道将文件路径或位置放在哪里
C:\Users\johnm\eclipse-workspace\W4A6\src\input.in
任何帮助都会很棒。
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class Encryption {
public static String readFile(String filename) throws IOException {
Scanner scanner = new Scanner(new File(filename));
String content = "";
while (scanner.hasNextLine()) {
content += scanner.nextLine();
}
return content;
}
}
【问题讨论】: