【问题标题】:copying files from sdcard to android internal storage directory将文件从 sdcard 复制到 android 内部存储目录
【发布时间】:2011-08-12 06:27:29
【问题描述】:

我使用以下几行在 android 内部存储中创建了一个目录:

File directory = getDir("template", Context.MODE_PRIVATE);

我需要从 sdcard 的这个“模板”目录中添加一些文件,有什么方法可以实现?

任何帮助表示赞赏..

谢谢

【问题讨论】:

    标签: android


    【解决方案1】:

    尝试使用此方法。因为你应该给出源文件名和目标文件名。

    private boolean copyFile(File src,File dst)throws IOException{
            if(src.getAbsolutePath().toString().equals(dst.getAbsolutePath().toString())){
    
                return true;
    
            }else{
                InputStream is=new FileInputStream(src);
                OutputStream os=new FileOutputStream(dst);
                byte[] buff=new byte[1024];
                int len;
                while((len=is.read(buff))>0){
                    os.write(buff,0,len);
                }
                is.close();
                os.close();
            }
            return true;
        }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-08
    • 2015-09-14
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多