The problem with the code below is a logic error, the android emulator
says the file I created on the sdcard is 1 byte. This app is supposed
to take a zcode file that is bundled in the apk file and put it onto
the sdcard. It only puts one byte onto the sdcard and I cannot figure
out why.
package wtaylorjr2001.thestargods;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.TextView;
import java.io.File;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import android.content.res.AssetManager;
import java.io.InputStream;
public class TheStarGodsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
setContentView(textView);
InputStream in;
FileOutputStream f;
byte[] buffer;
int size = 0;
int len;
AssetManager assetManager = getAssets();
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/Twisty");
dir.mkdirs();
File file = new File(dir, "test.z8");
try{
f = new FileOutputStream(file);
in = assetManager.open("test.z8");
size = in.available();
buffer = new byte[size];
while ((len = in.read(buffer, 0, size)) != -1){
f.write(in.read());
}
f.close();
in.close();
}
catch(IOException e){
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en