我发现我的代码中的错误/ mnt / sdcard / recycle:open失败:EISDIR(是一个目录)

时间:2013-11-18 05:51:42

标签: java android io

String inputPath= mFilePathTextView.getText().toString();
System.out.println("paa"+inputPath);

File outputPath = new File(Environment.getExternalStorageDirectory().toString()+"/recycle/");
System.out.println("paaa"+outputPath);
// File (or directory) to be moved
//String outputPath="/mnt/sdcard/";
//File dir = new File(outputPath);

if (!outputPath.exists()) {
    outputPath.mkdir();
}

in = new FileInputStream(inputPath);        
out = new FileOutputStream(outputPath);
byte[] buf = new byte[1024];
int len;

while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
}

in.close();
out.close();
// delete the original file
//new File(inputPath).delete(); 

我正在成功创建文件夹,但文件未在此文件夹上复制。我想移动任何类型的文件。

1 个答案:

答案 0 :(得分:0)

这可能有助于你

if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
  File  fDir = new File(android.os.Environment.getExternalStorageDirectory(),"recycle");

现在检查文件是否存在,同时确保在AndroidManifest.xml文件

中添加了必需的权限