您好我的应用程序我想将SharedPrefernces文件备份到我的设备存储。我尝试导出它,就像我导出我的数据库文件但它给了我一个错误。" java.io.filenotfoundexception / data / data / com.example.myapp / shared_prefs / myPref:open failed:ENOENT (没有这样的文件或难治) 这是我的代码:
@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();
}