Hey!
I'm trying to develop an app on android with processing that needs to save information in a table for next time use and then retrieve it later on. (Sort of like a leaderboard record). The problem is that saveTable() and loadTable() don't work because the error java.lang.IllegalArgumentException: File contains a path separator is returned.
Here is bascially what I'm trying to do (Which works fine on normal PC):
In setup:
try {
PersonalDetails = loadTable("AccountInfo.csv", "header"); // PersonalDetails is my table variable.
if (PersonalDetails.getRowCount() > 0) {
Registered = true;
LocalScore = PersonalDetails.getRow(0).getInt("Score");
}
}
catch (NullPointerException e) {
Table createCSV = new Table();
createCSV.addColumn("ID", Table.INT);
createCSV.addColumn("Score", Table.INT);
createCSV.addColumn("Name", Table.STRING);
saveTable(createCSV, "data/AccountInfo.csv");
PersonalDetails = loadTable("AccountInfo.csv", "header");
if (PersonalDetails.getRowCount() > 0) {
Registered = true;
LocalScore = PersonalDetails.getRow(0).getInt("Score");
}
}
And then in draw basically continuously save as score updates:
void draw() {
if (Start) {
if (Registered) {
PersonalDetails.setInt(0, "Score", LocalScore);
saveTable(PersonalDetails, "data/AccountInfo.csv");
}
}
background(255);
}
As for android I continued to get the error stated above. I've tried multiple solutions to try to fix this including an InputStream and BufferedReader, this read the file perfectly fine:
BufferedReader br;
String line;
void readInfo() {
try {
InputStream is = createInput("AccountInfo.txt");
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((line=br.readLine())!=null) {
System.out.println(line);
}
}
catch (IOException e) {
System.out.println("IOException when trying to read AccountInfo.txt:\n"+e);
System.exit(0);
}
}
But, every approach i've taken so far to try to write the file failed. I'm assuming read works better because it will auto search the /files/ directory when not specified with a path. So far i've tried to use a BufferedWriter and PrintWriter in the same way as readInfo() above, hoping it would work, but it didn't:
PrintWriter saveInformation;
BufferedWriter writer = null;
void saveInfo() {
try
{
writer = new BufferedWriter(new FileWriter("accountinfo.csv"));
saveInformation = new PrintWriter("accountinfo.csv");
saveInformation.println("Changed Text File...");
writer.write("Changed Text file...");
}
catch ( IOException e)
{
}
finally
{
try
{
if ( writer != null ) writer.close( );
if (saveInformation != null) saveInformation.close();
}
catch ( IOException e)
{
}
}
}
I have also tried to use the AssetManager, couldn't get that working. Also, I tried to use all above listed methods with relative file path and absolute file path. Each of these would similarly return the same error "java.lang.IllegalArgumentException: File contains a path separator".
Any help or feedback on the matter would be immensely very much greatly incredibly much appreciated!