I've been developping an app and I need to save internal data.
This has been quite a hit and miss adventure and I'm finally getting frustrated.
Here is what I have;
I do not understand why it seems like the file is being saved temporarily. I also don't think it's writing properly because it's being read elsewhere here:
Thanks for your help.
I've been trying to solve this for the past week.
This has been quite a hit and miss adventure and I'm finally getting frustrated.
Here is what I have;
Code:
private void ChkFile() {
file = getBaseContext().getFileStreamPath(filename);
String text;
if(!file.exists())
{
text = "Welcome to the Application";
try {
FileWriter DataFile = new FileWriter(filename);
PrintWriter out = new PrintWriter(DataFile);
out.print("Add New Entry...\n");
out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT);
toast.show();
}
else
{
text = "Welcome back!";
Toast toast = Toast.makeText(getApplicationContext(), file.getPath(), Toast.LENGTH_SHORT);
toast.show();
}
}
I do not understand why it seems like the file is being saved temporarily. I also don't think it's writing properly because it's being read elsewhere here:
Code:
public String [] getData()
{
String path = Menu.file.getPath();
String[] data = new String[GetN(path)];
try
{
BufferedReader content = new BufferedReader(new FileReader(path));
for(int i = 0;content.ready();i++)
data[i]=content.readLine();
}
catch (IOException e){e.printStackTrace();}
catch (Exception e) {e.printStackTrace();}
return data;
}
private int GetN(String file)
{
int counter = 0;
try
{
BufferedReader test = new BufferedReader(new FileReader(file));
while(test.readLine()!=null)
counter++;
}
catch(IOException ex)
{
System.out.println("FILE NOT FOUND");
}
return counter;
}
Thanks for your help.
I've been trying to solve this for the past week.