IO流

package three;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class IO {

    public static void main(String[] args) {
        File file = new File("data.txt");
        System.out.println("路径:"+file.getAbsolutePath());
        try {
            FileOutputStream out = new FileOutputStream(file);
            byte[] str = "12345abcdef@#%&*软件工程".getBytes();
            out.write(str);
            out.close();
        }catch(Exception e) {
            e.printStackTrace();
        }
        try {
            FileInputStream in = new FileInputStream(file);
            byte[] str1 = new byte[100];
            int length = in.read(str1);
            System.out.println("文件中的信息是:"+ new String(str1,0,length));
            in.close();
        }catch(Exception e) {
            e.printStackTrace();
        }
    }
}

 

 

posted on 2019-06-16 17:20  52.Hz  阅读(105)  评论(0编辑  收藏  举报