We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everybody, A month ago I started to make my own android app via processing. Now I’ve got the problem that I want to read some information’s about levels ( e.g. if they have been accomplished ) and the highscore from a csv file. I change the values of the cells in the csv with saveInt() and afterwards i save them with saveTable(). The Problem is , that if I type the loaded filename in the saveTable function, to save the changes witch I have made with saveInt , a new csv file is created in the sketch Folder instead of overwriting the existing file in the data directory. I tried to type data/ before the filename in saveTable(), which works perfectly in the normal java Mode. When i try to launch the Program in Android Mode, I get the following Exception:
FATAL EXCEPTION: Animation Thread Process: processing.test.gui_spiel2_ver_and_vers, PID: 6316 java.lang.IllegalArgumentException: File data/gamedata_2.csv contains a path separator
It seems like the saveTable function doesn´t accept paths in android mode.
Does someone know how to fix the Problem or a (hopefully simple) way to r/w and save the same csv file?
Hope some of you might help me :)
thank you!
Answers
@mago57::
/data does not mean nothing in android you can save to sdcard==
String directory = new String(Environment.getExternalStorageDirectory().getAbsolutePath() + "/moncsv.csv"); save(directory + "/" + filename);
or to raw folder, same kind of code but alittle more tricky
you can create a folder ("mkdirs()") you can verify that the file exists("exists()" or not, you can decide to replace the old one by the new one or to append...
dont forget to add write external storage permissions use name without uppercase and only with abcd...letters or 123456789 numbers
@akenaton
Thank you !! First of all I missed , that Android as a Linux based system needs an / before the Paths in saveTable() which was also mentioned in the reference .....
As you just mentioned, I had to wirte the changed csv file into a writable Directory.
With :
import android.os.Environment;.
you can use:
String str = Environment.getExternalStorageDirectory().getAbsolutePath(); saveTable(table,str+"filename");
to get a writable External storageDirectory in which you are " allowed" to write.
now you can read the changed file with :
import java.io.File;
if (file.exists()){ table = loadTable(str+"/filename", "header"); // first time your app runs or there haven´t been any changes to the file } else {
table = loadTable("filename_initial_data", "header"); // the changed file exists , so you read from it }
hope this might help some of you who have the same Problem :)
(PS: Don´t miss the r/w permissions in the Manifest and sry for spelling / grammar mistakes )
Have a nice Day !
mago57