FileOutputStream和FileInputStream

package one.string;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

public class TestString 
{
    public static void main(String[] args) 
    {        
        try 
        {            
            File file = new File("F:\\test1.txt");
            if(!file.exists())
            {
                file.createNewFile();
            }
            FileOutputStream fos = new FileOutputStream(file, true);
            fos.write("我很好,谢谢!and you?".getBytes("GBK"));
            fos.close();
            FileInputStream fis = new FileInputStream(file);
            byte[] bt = new byte[1024];
            int len = fis.read(bt);
            fis.close();
            System.out.println(new String(bt,0,len));
            
        }
        catch (FileNotFoundException e) 
        {
            e.printStackTrace();
        }
        catch (IOException e) 
        {
            e.printStackTrace();
        }
        
    }
}

 

posted @ 2014-03-06 16:51  奋斗?坑  阅读(421)  评论(0编辑  收藏  举报