Java读写记事本文件

编程入门 行业动态 更新时间:2024-10-25 00:30:42

Java读写<a href=https://www.elefans.com/category/jswz/34/1768827.html style=记事本文件"/>

Java读写记事本文件

Java中我们也会考虑读写记事本,文件读取如下:

public static void main(String[] args) {try {String path="d:\\abc.txt";//定义文件路径名称//文件输入流FileInputStream fs= new FileInputStream(path);//内存输入流InputStreamReader is=new InputStreamReader(fs);BufferedReader br=new BufferedReader(is);String line=br.readLine();            while(line!=null){System.out.println(line);line=br.readLine();}//释放资源
            br.close();is.close();fs.close();            } catch (FileNotFoundException e) {// TODO Auto-generated catch block
            e.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch block
            e.printStackTrace();}}

 

 文件写入如下:

public static void main(String[] args) {try {String path="d:\\duanjt.txt";String str= System.getProperty("line.separator");//换行符String reout="duanjt"+str+"中华人民共和国"+str+"第三行";FileOutputStream fos=new FileOutputStream(path);            fos.write(reout.getBytes());fos.close();System.out.println("文件写入成功");} catch (FileNotFoundException e) {// TODO Auto-generated catch block
            e.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch block
            e.printStackTrace();}}

 

多的就不说了,代码比较简单,清晰明了

转载于:.html

更多推荐

Java读写记事本文件

本文发布于:2024-03-08 22:11:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1722592.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:记事本   文件   Java

发布评论

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

>www.elefans.com

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