なんか直接はできないみたい。
なので、使用前に saveSetting, 使用後に loadSetting で取り合えず使える。
※ ディフォルトのファイル名は、”パッケージ名+_preferences.xml”
void public saveSetting( Context c, String exterernalPath) {
String to = c.getFilesDir().getParentFile().getAbsoluteFile() + "/shared_prefs/my_setting.xml";
// 外部SD->内部SD
copyFile( exterernalPath, to ) ;
}
void public loadSetting( Context c, String exterernalPath) {
String to = c.getFilesDir().getParentFile().getAbsoluteFile() + "/shared_prefs/my_setting.xml";
// 内部SD->外部SD
copyFile( to, exterernalPath ) ;
}
public static void copyFile(String srcFilePath, String dstFilePath) {
File srcFile = new File(srcFilePath);
File dstFile = new File(dstFilePath);
// ディレクトリを作る.
File dstPath = new File(dstFile.getParent());
dstPath.mkdirs();
try {
// ファイルコピーのフェーズ
InputStream input = null;
OutputStream output = null;
input = new FileInputStream(srcFile);
output = new FileOutputStream(dstFile);
int DEFAULT_BUFFER_SIZE = 1024 * 4;
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
input.close();
output.close();
} catch (Exception e) {
e.printStackTrace();
}