今天写个小东西时,遇到了如下的错误消息:
Consumer closed input channel or an error occurred. events=0x8
Channel is unrecoverably broken and will be disposed!
后来,找到了错误的原因:
public class FileDo {
public void saveToSDCard(String filename,String content) throws Exception{
String path =Environment.getExternalStorageDirectory()+File.separator+"mytxt"+File.separator;
// File file =new File(path);
// if(!file.exists()){
// file.mkdir();
// }
FileOutputStream outStream =new FileOutputStream(path+filename+".txt");
outStream.write(content.getBytes());
outStream.close();
}
}
错误的原因就是,原先没有写注释的部分,也就是第一次保存指定路径的文件时,SD卡不存在mytxt目录,当然了,SD卡不存在mytxt时,首先要创建mytxt目录。
今天写个小东西时,遇到了如下的错误消息:
Consumer closed input channel or an error occurred. events=0x8
Channel is unrecoverably broken and will be disposed!
后来,找到了错误的原因:
public class FileDo {
public void saveToSDCard(String filename,String content) throws Exception{
String path =Environment.getExternalStorageDirectory()+File.separator+"mytxt"+File.separator;
// File file =new File(path);
// if(!file.exists()){
// file.mkdir();
// }
FileOutputStream outStream =new FileOutputStream(path+filename+".txt");
outStream.write(content.getBytes());
outStream.close();
}
}
错误的原因就是,原先没有写注释的部分,也就是第一次保存指定路径的文件时,SD卡不存在mytxt目录,当然了,SD卡不存在mytxt时,首先要创建mytxt目录。