是否可以使用android中的openFileOutput方法在“/data/data/packagename/files/”目录下创建的子目录中创建文件?
即“/data/data/packagename/files/”目录中有一个名为“text”的子目录。
我想使用 openFileOutput(String name, int mode) 方法将文件eg:sample.txt写入此目录....
是否可以使用 openFileOutput 方法来做到这一点......
谁可以帮我这个事....
不能使用 openFileOutput,但您可以使用常规的 java.io.File 方法。
java.io.File.mkdir()
创建目录,例如将文件从 sdcard 复制(可以调整创建)到某些数据子目录:
public static final void copyfile(String srFile, String dtFile){
Log.d(MyApp.APP,"copyfile " + srFile + " -> " + dtFile );
try{
File f1 = new File(srFile);
File f2 = new File(dtFile);
InputStream in = new FileInputStream(f1);
OutputStream out = new FileOutputStream(f2);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0){
out.write(buf, 0, len);
}
in.close();
out.close();
Log.d(MyApp.APP,"File copied to " + f2.getAbsolutePath());
} catch(FileNotFoundException ex){
Log.e(MyApp.APP,"Error.",ex);
} catch(IOException e){
Log.e(MyApp.APP,"Error.",e);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)