Android Savefile,Openfile,Writefile processing 3.0.1...THE EASY WAY!!!

edited December 2015 in Android Mode

im writing a visualiser and need save and load settings here is a quick save file function.

still working on the string save function and open function.

got this from stackoverflow works to save file to Android internal storage SDCARD.

import android.os.Environment; // need this for Environment Android stuff

public void SaveFile() {

try { String filename="visualiser.txt"; String directory = new String(Environment.getExternalStorageDirectory().getAbsolutePath() ); save(directory + "/" + filename); } catch (Exception e) {

} }

just call SaveFile(); or what ever you want to call it... you will need to set sketch permissions to WRITE_EXTERNAL_STORAGE for file io.

anyone know of a simple method to read write load file into a string.

seen a few methods but it seems overly complicated. createbuffer writebuffer etc.

im no expert in android or java so dont ask me how this works. but its sort of easy to follow. ( declare name/find path/savefile/catch error etc).

Answers

  • edited December 2015

    added a bit more to save any value using str() to string.

    public void SaveFile() {

    try { String filename="visualiser.txt";

    String words = "Zmod"+str(Zmod)+"Mmod"+str(Mmod)+"Smod"+str(Smod)+"Fmod"+str(Fmod); String[] list = split(words, ' ');

      String directory = new String(Environment.getExternalStorageDirectory().getAbsolutePath() ); 
      saveStrings(directory + "/" + filename,list); } catch (Exception e) {} 
    

    }

    this saved the file in internal sdcard with my presets..... I don't know why this wont post code properly on here as usual.

  • edited December 2015

    import android.os.Environment;

    public void SaveFile() {

    try {
    String filename="visualiser.txt";

       String[] list = {"X"+str(Xmod),"Y"+str(Ymod)}; //write list style
      String directory = new String(Environment.getExternalStorageDirectory().getAbsolutePath() ); 
      saveStrings(directory + "/" + filename,list); } catch (Exception e) {} 
    

    }

    public void LoadFile() {

    try { String filename="visualiser.txt"; String directory = new String(Environment.getExternalStorageDirectory().getAbsolutePath() );
    String[] load = loadStrings(directory+ "/"+ filename); for (LC=0; LC<load.length; LC++) { //for loop load to global array. dataload[LC]=load[LC]; //dataload global string, load local string. }

    dataloadlength = load.length; // this is for length number of lines. } catch (Exception e) {} }

    and that's it SAVEFILE WRITEFILE LOADFILE Android....took me a day but got it at last.....!!!!

    it still wont post code correctly on here don't know why but this works great tested on android 4.1

  • THAT S EVIDENT

  • Please format your code

Sign In or Register to comment.