file的写操作

//将name写到磁盘的txt文件中
public void write(String name,String path) {
System.out.println("这是为什么呢?");
File file = new File(path);
try {
file.mkdirs();
FileOutputStream fos = new FileOutputStream(file, true);
byte[] b = name.getBytes();
fos.write(b, 0, b.length);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

你可能感兴趣的:(File)