我已在设备中安装了应用,但无法在SD卡上找到它。 我将/data/data/com.abc.xyz/databases路径作为安装路径。但它没有在SD卡中显示。
实际上我是从res / raw文件夹解压缩SD卡中的文件。
只是想知道我的数据去了哪里?如何读写SD卡数据。
以下是代码
final InputStream myInput = new GZIPInputStream( this.myContext.getResources( ).openRawResource(
R.raw.clc_android ) );
String dir = Environment.DIRECTORY_DCIM;
final String outFileName = DB_PATH+DB_NAME;
if (new File(DB_PATH).exists() == false) {
new File(DB_PATH).mkdirs();
}
final OutputStream myOutput = new FileOutputStream( outFileName );
//transfer bytes from the inputfile to the outputfile
final byte[ ] buffer = new byte[ 1024 ];
int length;
while ( ( length = myInput.read( buffer ) ) > 0 )
{
myOutput.write( buffer, 0, length );
}
下面是android清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.clc.encyclopedia" android:versionCode="23"
android:versionName="14.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="20" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
答案 0 :(得分:0)
您好我可以告诉您如何通过SD卡复制数据库。我尝试修改您发布的代码,见下文。
private static String EXTERNAL_STORAGE = Environment.getExternalStorageDirectory().getPath();
private static String DIR_APP_HOME = "yourapphome";
private static String getExternalStoragePath() {
return new StringBuilder().append(EXTERNAL_STORAGE).append("/").toString();
}
public static String appHomeDirectory() {
return new StringBuilder().append(getExternalStoragePath()).append(DIR_APP_HOME).append("/").toString();
}
public static void verifyAppHomePath() {
File mFile = new File(appHomeDirectory());
if (!mFile.exists()) {
mFile.mkdir();
}
mFile = null;
}
现在如何使用代码中的所有函数。这将在您的SD卡内创建您想要的名称。
final InputStream myInput = new GZIPInputStream( this.myContext.getResources( ).openRawResource(R.raw.clc_android ) );
String dir = Environment.DIRECTORY_DCIM;
// this will verify the directory is present or not if not present then it will create the empty directory
verifyAppHomePath();
// assign the your application home directory
DB_PATH = appHomeDirectory();
// build the database path with database file name
final String outFileName = DB_PATH+DB_NAME;
final OutputStream myOutput = new FileOutputStream( outFileName );
//transfer bytes from the inputfile to the outputfile
final byte[ ] buffer = new byte[ 1024 ];
int length;
while ( ( length = myInput.read( buffer ) ) > 0 )
{
myOutput.write( buffer, 0, length );
}
如果您有任何疑问,请告诉我,如果您不知道如何访问SD卡数据库,请告诉我。谢谢。