java FileOutputStream和FileInputStream简单案例

public class FileTest {


public static void main(String[] args) {
File file = new File("D:/mywork","work.txt");
try {
FileOutputStream out =  new FileOutputStream(file);
byte [] buy = "我要上春晚 蒙克".getBytes();
out.write(buy);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
FileInputStream in = new FileInputStream(file);
byte byt[] =new byte[1024];
int length = in.read(byt);
System.out.println("文件中的内容为:"+new String(byt,0,length));
} catch (Exception e) {
e.printStackTrace();
}
}


}

打印结果:

文件中的内容为:我要上春晚 蒙克

你可能感兴趣的:(编程语言)