我用下面的code,试图将我的数据库文件,以我的SD卡。我有不同之处在于我获得下 SD
A红线没有问题。有任何想法吗?
I'm using the code below to try and move my database file to my sdcard. I have no problems except that I get a redline under sd
. Any ideas?
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "\\data\\application.package\\databases\\name";
String backupDBPath = "name";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src;
try {
src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
try {
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
您只能使用一个变量,如果你创建了一个实例:
You can only use a variable if you create an instance of it:
将这个:
File sd = Environment.getExternalStorageDirectory();