Reputation: 2753
I am making an Android application, and I would like to add two files named fsx.xml
and xplane.xml
. This is the code I am using, it runs perfectly without errors, but the /planesim
just appears empty. Please help!
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());
}
}
}
Thanks for your time and help, zeokila.
Upvotes: 1
Views: 619
Reputation: 137332
This is your mistake:
for (int fileCount = 1; fileCount == 2; fileCount++)
which is like:
int fileCount = 1;
while(fileCount == 2) // never true...
The for loop never executed (because 1 != 2
), should be:
for (int fileCount = 1; fileCount <= 2; fileCount++)
Upvotes: 1