Android复制/DEV/LOG/*到SD卡失败器



伙计

new to android,这是我在stackoverflow中的第一篇文章。我认为是时候让我参与其中了。

当我尝试将位于/dev/log/*的系统日志复制到我的SD卡中时,已经存在一个问题SD卡。所以我在下面有我的代码:

private final String srcLocation = "/dev/log/radio";
private final String desLocation = "/mnt/sdcard/radio";
FileInputStream src;
FileOutputStream dst;
FileChannel mFCsrc;
FileChannel mFCdst;
public boolean copyFile(String sourceLocation, String destLocation) throws IOException {
          try {
                File sd = Environment.getExternalStorageDirectory();
                if(sd.canWrite()){
                    File source=new File(sourceLocation);
                    File dest=new File(destLocation);
                    if(!dest.exists()){
                        dest.createNewFile();
                    }
                    if(source.exists()){
                        src = new FileInputStream(source);
                        dst = new FileOutputStream(dest);
                        mFCsrc = src.getChannel();
                        mFCdst = dst.getChannel();
                        mFCsrc.transferTo(0, mFCsrc.size(), mFCdst);
                    }
                }
                return true;
            } catch (Exception ex) {
                ex.printStackTrace();
                return false;
            } finally {
                if (mFCsrc != null) {
                    mFCsrc.close();
                }
                if (mFCdst != null) {
                    mFCdst.close();
                }
            }
    }

我确实在我的SD卡中有文件,我可以从DDMS窗口中看到它,但它的大小为0。因此,有人知道吗?谢谢。/p>

您应该调试。用调试器踩下代码,然后检查正在发生的事情。

可能正在发生的随机事情,但是我们无法确定:如果"源"不存在,您将创建dest,但是由于source.exists()会返回false,因此您不做任何事情。您最终会以当前行为,一个新创建的文件。

最新更新