I am trying to read a text file into an array, modify the array, and then store it back into the text file for future use.
The array is just one column wide, so I would like each line of the text file to be stored in each array element.
I am doing this in the middle of a big program, so the related answers which I've found before don't seem to fit in.
Here is my code:
checkReadHeader = parts[0];
if (checkReadHeader.equals("LETSDOIT"))
{
readMsg = parts[1];
readj = 0;
if(readMsg.equals(logging1)){
//---------------------------------------
// READ readlist1.txt AND STORE IT INTO STRING ARRAY readlist
//---------------------------------------
try
{
fIn = context.openFileInput("readList1.txt");
isr = new InputStreamReader(fIn);
while ((charRead = isr.read(inputBuffer)) > 0)
{
String readString = String.copyValueOf(inputBuffer, 0, charRead);
if(!readString.equals("\n"))
{
readList[readj][0] += readString;
}
else
{
readj += 1;
}
inputBuffer = new char[100];
}
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
//---------------------------------------
// MODIFY readlist
//---------------------------------------
readList[j][0] = testdate;
//---------------------------------------
// STORE readlist BACK INTO TEXT FILE readlist1.txt
//---------------------------------------
try
{
fOut = context.openFileOutput("readList1.txt", context.MODE_WORLD_READABLE);
osw = new OutputStreamWriter(fOut);
osw.write(readList.toString());
osw.flush();
osw.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
My declaration of variables are all ok, as I am only coming across a run-time error now. Please advise me of any errors in my code - thanks in advance:-)