jeudi 19 mars 2015

Android app not creating or editing a .csv file


I have been working on this for a few weeks now a little bit at a time. This is an android app i am developing for multiple versions of Samsung tablets. I need to create a file and add text to it. I cannot do either. I have 2 different methods to add text using different text writers to add text to a file. Here is my code:



public void addTextToFile(String text) {
File logFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS), "MyFile.csv");
if (!logFile.exists()) {
try {
logFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true));
buf.append(text);
buf.newLine();
buf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void write(String data){
OutputStream os;
OutputStreamWriter osw;
data += "\n";
try {
os = new FileOutputStream(file, true);
osw = new OutputStreamWriter(os);
osw.write(data);
osw.flush();
osw.close();
} catch (Exception e) {
e.printStackTrace();
}
}




Aucun commentaire:

Enregistrer un commentaire