0
你好我的应用程序我想备份SharedPrefernces文件到我的设备存储。我试图导出它像我出口我的数据库文件,但它给了我一个错误。“java.io.filenotfoundexception/data/data/com.example.myapp/shared_prefs/myPref:打开失败:ENOENT(没有这样的文件或diractory) 这里是我的代码:如何导出我的sharedPreferences文件
@SuppressLint("SdCardPath")
private void exportPref() throws IOException {
// Open your local db as the input stream
try {
String inFileName = "/data/data/com.bibas.workclocks/shared_pref/"+MySharedPreferences.MY_TEMP;
File dbFile = new File(inFileName);
FileInputStream fis = new FileInputStream(dbFile);
String outFileName = Environment.getExternalStorageDirectory()+ "/MyPrefs";
// Open the empty db as the output stream
OutputStream output = new FileOutputStream(outFileName);
// transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
// Close the streams
output.flush();
output.close();
fis.close();
} catch (Exception e) {
Toast.makeText(context, e.toString(), Toast.LENGTH_LONG)
.show();
}
Toast.makeText(context,
"'",
Toast.LENGTH_LONG).show();
}
但是从DDMS我可以将文件导入到我的电脑.. – Matt 2014-09-02 02:19:50
对不起马特,我做有点额外的研究,并发现我的最初假设是不正确的。 – 2014-09-02 02:21:26
哇,我搜索了很长时间,谢谢。如果我想从我的应用程序导入它可能吗? – Matt 2014-09-02 02:36:22