我从教程中找到了这段代码,但它不起作用。
说目录不能创建
try {
myInput = new FileInputStream("//data//net.learn2develop.Databases//databases//MyDB");//this is
// the path for all apps
//insert your package instead packagename,ex:com.mybusiness.myapp
// Set the output folder on the SDcard
// File directory = new File(Environment.getExternalStorageDirectory().getPath());
File directory = new File("/sdcard/some_folder");
// Create the folder if it doesn't exist:
if (!directory.exists())
{
directory.mkdirs();
}
// Set the output file stream up:
// OutputStream myOutput = new FileOutputStream("/sdcard/");
OutputStream myOutput = new FileOutputStream(directory.getPath()+
"/database_name.backup");
// Transfer bytes from the input file to the output file
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0)
{
myOutput.write(buffer, 0, length);
}
// Close and clear the streams
myOutput.flush();
myOutput.close();
myInput.close();