从文本文件中读取字符串以插入输入(reading a string from text file to be inserted into input)

编程入门 行业动态 更新时间:2024-10-28 09:27:15
从文本文件中读取字符串以插入输入(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(); }

更多推荐

本文发布于:2023-07-23 22:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1238172.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   文本文件   reading   string   input

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!