从文本文件中读取字符串以插入输入(reading a string from text file to be inserted into input)
假设我有一个文件名“abc.txt”
这个文件有三个字符串“你好吗”
我想把字符串读作“你好吗”
并将其存储到字符串word2?
我该怎么做 ?
Lets say i has a file name "abc.txt"
This file has three strings " how are you "
I would like to read the strings as "how are you"
and store it into a string word2 ?
How can i do it ?
最满意答案
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(); } 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(); }更多推荐
发布评论