[英]reading a string from text file to be inserted into input
假設我有一個文件名“abc.txt”
這個文件有三個字符串“你好嗎”
我想把字符串讀作“你好嗎”
並將其存儲到字符串word2?
我該怎么做 ?
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();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.