Channel is unrecoverably broken and will be disposed!

来源:互联网 发布:美工的电脑为什么 编辑:程序博客网 时间:2024/05/21 01:44

今天写个小东西时,遇到了如下的错误消息:

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目录。
原创粉丝点击