hello all the tutorial on android external data storage are driveing me nuts
i have a OnOptionsCreatemenu that has 2 buttons "save" and "load" save works fine but load does not here is my code it wont let me iv commented down in the code also how do i make it let me save it in my own directory?...iv read every single tutorial on saving to ext storage like 5 times.....im just to dumb to get it! (please no links) then please make it into a new tutorial because it will be the most simplest breakdown of android ext data storage that even retarded chimpanzes like myself would understand
this is all meant to be one chunk of code......not sure why the code is showing in 2 codeboxes???
p.s sorry its my first time.....be easy ;)
private void save() {
String saveLine = ((EditText)
findViewById(R.id.captain)).getText().toString().trim();
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"/myfile.txt");
try {
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(saveLine);
bw.close();
Toast.makeText(getApplicationContext(),"File saved!",Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"Error writing file!",Toast.LENGTH_LONG).show();
}
{
//here it says i need to put a variable? why wont it let me use it like the save() function????
private void load() {
// ensure();
sdcard = Environment.getExternalStorageDirectory();
File file1 = new File(sdcard,"/myfile.txt");
try {
BufferedReader br = new BufferedReader(new FileReader(file1));
String loadline;
if ((loadline = br.readLine()) != null) {
String content=loadline.toString();
((EditText)
findViewById(R.id.captain)).setText(content);
}
br.close();
}
catch (IOException e) {
Toast.makeText(getApplicationContext(),"Error reading file!",Toast.LENGTH_LONG).show();
}
}