1、在磁盘上创建文件
File f1 = new File("e:\\a.txt");
System.out.println("createNewFile:" + f1.createNewFile());//打印创建状态
2、向指定文件,写入数据。
(1)创建输出流(jvm——》磁盘)
FileOutputStream fos = new FileOutputStream("e:\\a.txt");
// Creates a file output stream to write to the file with the specified name.
(2)将待写入数据,转换为字节数组。
String s = "ABCDE";
byte[] bys = s.getBytes();
(3)将字节数据,写入流中。
fos.write(bys, 0, 4);
(4)关闭流
fos.close();