日期:2014-05-20 浏览次数:21067 次
import java.io.*;
public class In {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Test.txt")));
out.writeBytes("somebody \n");
}catch(IOException e) {
System.out.println("No File!!!!!!!!");
}
}
}
/**
* Created by IntelliJ IDEA.
* User: admin
* Date: 2011-10-10
* Time: 11:40:58
* To change this template use File | Settings | File Templates.
*/
import java.io.*;
public class In {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
DataOutputStream out=null;
try{
out= new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Test.txt")));
out.writeBytes("somebody \n");
out.flush();
}catch(IOException e) {
e.printStackTrace();
// System.out.println("No File!!!!!!!!");
}finally{
try{
out.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
}
------解决方案--------------------
flush close() 加上应该可以
首先要清空缓冲区里的数据 再关闭流
------解决方案--------------------
package com.qq.server.model;
import java.io.*;
public class MyQqServer
{
public static void main(String args[])
{
File f=new File("d:/t.txt");
FileOutputStream fos=null;
byte[] b=new byte[1024];
int n=0;
try {
fos=new FileOutputStream(f);
String s="aa ";
fos.write(s.getBytes());
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
------解决方案--------------------
上面是正解
------解决方案--------------------