Friday, May 3, 2013

[android help] can not open files with openFileInput saved via openFileOutput



Thread thread = new Thread() {

@Override
public void run() {
try {
saveDataFromWeb();// here i write data into a file
} catch (Throwable e) {
AlertDialog.Builder builder = new AlertDialog.Builder(
findViewById(R.id.viewpager).getContext());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
sw.toString();
builder.setMessage(sw.toString());
AlertDialog alert = builder.create();
alert.show();
}
}
};
if (CONDITION) {
thread.start();
parseData("ThisWeekDatabase"); // here I read the data from the
parseData("NextWeekDatabase");
}


I found the error. It is because the thread is not done with it's work (writing data from the web into files) when I try to read these files. Now I need a way to "wait" for the thread so it has finished writing the files when parseData(xyz) needs them.


also either the way I write the data into the file or the way I read the data from the files is wrong because I get one single long line when I read out of the files I have written in before instead of multiple short lines.


I get



div.lvsdrt {background-color:#e3f1ff; border-top:black 1px dotted;padding:0.1em;}div.lvwer{background-color:#f2f9ff;border-top:black 1px dotted;padding:0.1em;}div.nobreak {page-break-inside:avoid;}


instad of



div.lvsdrt {
background-color:#e3f1ff;
border-top:black 1px dotted;
padding:0.1em;
}
div.lvwer {
background-color:#f2f9ff;
border-top:black 1px dotted;
padding:0.1em;
}
div.nobreak {
page-break-inside:avoid;
}


.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...