有关java字节流输出时异常抛出问题

2025-01-20 01:49:05
推荐回答(1个)
回答1:

把out定义在外面

public static void main(String args[]){
File f;
OutputStream out;
f=new File("e:"+File.separator+"test.doc");
try{
out=new FileOutputStream(f);
}
catch(FileNotFoundException e){
e.printStackTrace();
}
String str="asdfasdfasdf";
byte b[]=str.getBytes();
try{
out.write(b);}
catch(IOException e){
e.printStackTrace();
}
out.close();

}