【发布时间】:2011-08-12 06:27:29
【问题描述】:
我使用以下几行在 android 内部存储中创建了一个目录:
File directory = getDir("template", Context.MODE_PRIVATE);
我需要从 sdcard 的这个“模板”目录中添加一些文件,有什么方法可以实现?
任何帮助表示赞赏..
谢谢
【问题讨论】:
标签: android
我使用以下几行在 android 内部存储中创建了一个目录:
File directory = getDir("template", Context.MODE_PRIVATE);
我需要从 sdcard 的这个“模板”目录中添加一些文件,有什么方法可以实现?
任何帮助表示赞赏..
谢谢
【问题讨论】:
标签: android
尝试使用此方法。因为你应该给出源文件名和目标文件名。
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;
}
【讨论】: