我正在制作一个 Android 应用程序,我想添加两个名为fsx.xml
和的文件xplane.xml
。这是我正在使用的代码,它运行完美,没有错误,但/planesim
只是显示为空。请帮忙!
String planesimFolderName = "/planesim";
String fsxFile = "fsx.xml";
String xplaneFile = "xplane.xml";
String asset;
File assetDestination;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
final File planesimFolder = new File(Environment.getExternalStorageDirectory() + planesimFolderName);
final AssetManager assetManager = getAssets();
for (int fileCount = 1; fileCount == 2; fileCount++) {
if (fileCount == 1) {
asset = fsxFile;
} else if (fileCount == 2) {
asset = xplaneFile;
}
assetDestination = new File(Environment.getExternalStorageDirectory() + planesimFolderName + "/" + asset);
try {
InputStream in = assetManager.open(asset);
FileOutputStream f = new FileOutputStream(assetDestination);
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = in.read(buffer)) > 0) {
f.write(buffer, 0, len1);
}
f.close();
} catch (Exception e) {
Log.d("CopyFileFromAssetsToSD", e.getMessage());
}
}
}
感谢您的时间和帮助,zeokila。