eclipse中Java BufferedWriter使用.write方法异常,内容写不进文件里面。
packagefxn.usejava.notedpad;importjava.io.*;publicclassTest{publicstaticvoidmain(Stri...
package fxn.usejava.notedpad;
import java.io.*;
public class Test {
public static void main(String[] args) {
FileWriter fw = null;
BufferedWriter bfw = null;
try {
fw = new FileWriter("E:/JavaDev/others/hello.txt");
bfw = new BufferedWriter(fw);
bfw.write("I LOVE YOU,BABY!");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
fw.close();
bfw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
想实现的功能:在hello.text中加入一句话:I IOVE YOU,BABY!
抛出异常:文件流在写入前已被关闭
java.io.IOException: Stream closed
at sun.nio.cs.StreamEncoder.ensureOpen(Unknown Source)
at sun.nio.cs.StreamEncoder.write(Unknown Source)
at java.io.OutputStreamWriter.write(Unknown Source)
at java.io.BufferedWriter.flushBuffer(Unknown Source)
at java.io.BufferedWriter.close(Unknown Source)
at fxn.usejava.notedpad.Test.main(Test.java:21)
求大神指点破解方法。。。。。 展开
import java.io.*;
public class Test {
public static void main(String[] args) {
FileWriter fw = null;
BufferedWriter bfw = null;
try {
fw = new FileWriter("E:/JavaDev/others/hello.txt");
bfw = new BufferedWriter(fw);
bfw.write("I LOVE YOU,BABY!");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
fw.close();
bfw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
想实现的功能:在hello.text中加入一句话:I IOVE YOU,BABY!
抛出异常:文件流在写入前已被关闭
java.io.IOException: Stream closed
at sun.nio.cs.StreamEncoder.ensureOpen(Unknown Source)
at sun.nio.cs.StreamEncoder.write(Unknown Source)
at java.io.OutputStreamWriter.write(Unknown Source)
at java.io.BufferedWriter.flushBuffer(Unknown Source)
at java.io.BufferedWriter.close(Unknown Source)
at fxn.usejava.notedpad.Test.main(Test.java:21)
求大神指点破解方法。。。。。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询