I am trying to get a file to save to my sdcard. Here is the code I have so far. I really appreciate any help you can offer. Thanks
Edit:
The problem is that the file is not saved. When I exit the program and look at the sdcard no file was saved. I put a toast into the error catchers and it looks like I’m getting an IOException. I don’t know how to check the StackTrace log though
class bSaveListen implements Button.OnClickListener{
@Override
public void onClick(View arg0) {
savef();
}
}
public void savef(){
sdCard = Environment.getExternalStorageDirectory();
String filename = "aaaaaaa.txt";
file = new File(sdCard, filename);
FileOutputStream fileout;
byte[] thatString = new String("awesome string").getBytes();
try {
fileout = new FileOutputStream(file);
fileout.write(thatString);
fileout.flush();
fileout.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
I spent all day today trying to figure this out and I finally have an answer. Just thought I would post it here in case anyone else is having a similar issue. I stupidly wrote my permission inside the application block of code instead of below it. Should be like this
Not like this