假设我的文件名为“abc.txt”
此文件有三个字符串“你好吗”
我想把字符串读作“你好吗”
并将其存储到字符串word2中?
我该怎么办?
答案 0 :(得分:4)
try
{
File file = new File("abc.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String word2 = br.readLine();
br.close();
//test:
System.out.println(word2);
} catch (IOException e)
{
// Something went wrong, eg: file not found
e.printStackTrace();
}