欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JAVA-BufferedWriter写入文件没有内容

程序员文章站 2022-04-29 08:59:03
JAVA-BufferedWriter写入文件没有内容,尝试flush()和close()也没效果public class BufferReader {public static void main(String[] args) {BufferedWriter bw=null;BufferedReader br=null;try {bw=new BufferedWriter(new FileWriter(“G:\datetest715\715.txt”));br=new BufferedRea...

JAVA-BufferedWriter写入文件没有内容,尝试flush()和close()也没效果

public class BufferReader {
public static void main(String[] args) {
BufferedWriter bw=null;
BufferedReader br=null;
try {
bw=new BufferedWriter(new FileWriter(“G:\datetest715\715.txt”));
br=new BufferedReader(new FileReader(“G:\datetest715\715.txt”));
bw.write(“1234567\r\n”);
bw.flush();
bw.write(“321”);
bw.flush();
String str=null;
while((str=br.readLine())!=null) {
System.out.println(str);
}

		br.close();
		
		
		
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}

}

最后发现是文件路径有问题
改成
bw=new BufferedWriter(new FileWriter(“G:\datetest715/715.txt”));
br=new BufferedReader(new FileReader(“G:\datetest715/715.txt”));
成功!原来是斜杠的问题。

本文地址:https://blog.csdn.net/weixin_43580640/article/details/107371808

相关标签: java io java