1、FileOutputStream类
在该类中,对于写入和关闭资源的操作需要进行异常捕获,常见操作如下:
FileOutputStream fos = null;
try{
fos = new FileOutputStream(dst_file);
for(File file:list)
{
//写入的是相对路径,绝对路径为file.getAbsolutePath()
fos.write((file.getName()+System.lineSeparator()).getBytes());
}
}
finally {
if (fos!=null)
{
try{
fos.close();
}
catch (IOException e){
throw new RuntimeException("系统资源关闭失败");
}
}
}