File dst = new File(dstPath);
该变量
dstPath具有完整的目标路径,包括文件名,这是错误的。这是正确的代码片段:
String dstPath = Environment.getExternalStorageDirectory() + File.separator + "myApp" + File.separator;File dst = new File(dstPath);exportFile(pictureFile, dst);
private File exportFile(File src, File dst) throws IOException { //if folder does not exist if (!dst.exists()) { if (!dst.mkdir()) { return null; } } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File expFile = new File(dst.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); FileChannel inChannel = null; FileChannel outChannel = null; try { inChannel = new FileInputStream(src).getChannel(); outChannel = new FileOutputStream(expFile).getChannel(); } catch (FileNotFoundException e) { e.printStackTrace(); } try { inChannel.transferTo(0, inChannel.size(), outChannel); } finally { if (inChannel != null) inChannel.close(); if (outChannel != null) outChannel.close(); } return expFile;}
感谢您的提示。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)