0
안녕하세요. 내 애플리케이션의 SharedPrefernces 파일을 내 장치 저장소로 백업하고 싶습니다. 필자는 데이터베이스 파일을 내보내는 것처럼 내 보내려했지만 내게 오류가 발생했습니다. "java.io.filenotfoundexception/data/data/com.example.myapp/shared_prefs/myPref : open failed : 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
매트 죄송합니다, 내가 그랬어 약간의 추가 연구를 통해 초기 가정이 잘못되었음을 발견했습니다. –
와우, 오랫동안 고마워요. 내 응용 프로그램에서 가져 오기를 원한다면 가능합니까? – Matt