Android Mode saving and loading txt file


I’m having trouble saving and loading .txt files on android mode sketch. I have looked at past discussions about how to resolve the problem but it makes no sense to me.
What’s the difference in saving and loading .txt files on java mode and android mode? And how do you resolve the problem?

Any info helps @imaginativeCODE.


No problem guys I think I found a way to do it.


I found that if you put your “example.txt” inside a folder called data and put the data folder inside of your sketch folder then it loads up just fine.

p.s. this works with images and all other things you want to save and load. Also don’t write the “loadStrings” or “loadImage” like this - “loadStrings(“data/Example.txt”)”. The way I found to load and save is like this - “loadStrings(“Example.txt”)”. I don’t know why this works? But it does!

Here’s some example code below and images

PImage ExampleImage;
String[] ExampleText = new String[1];

void setup() {
  ExampleImage= loadImage("TestImage.png");
  ExampleText = loadStrings("TestStrings.txt");

void draw() {
  image(ExampleImage, 0, 0, width, height);
  text(ExampleText [0], width/2 - textWidth(ExampleText [0])/2, height/2);

Inside of sketch folder

Inside of data folder

Keep in mind that in future processing updates they might do it differently. I spent lots of time going threw old posts that didn’t work any more. I just had to figure it out by myself. Hope this helps some of you people trying to solve this.


sorry, i not understand why you say

Also don’t write the “loadStrings” or “loadImage” like this - “loadStrings(“data/Example.txt”)”.

as i would think it is actually the good way?

// processing 3.4   / Java Mode

// pls make a subdir /data/
// and have the file there as
// /data/HalloWorld.txt
// if the file is not found you get that red warning
// The file "HalloWorld.txt" is missing or inaccessible, make sure the URL is valid
// or that the file has been added to your sketch and is readable.

// String filename1="HalloWorld.txt";
// you see, no path info given here, so the /data/ dir is assumed as default and works 
// but

String filename1="data/HalloWorld.txt";

// is actually a good way to do it.

// for saving a file we read:
// By default, this file is saved to the sketch's folder.
// but we don't want that there!
// to be more compatible to the loadStrings command
// the example should be changed to also using the /data/ dir.

String filename2="data/HalloWorld_copy.txt";

// funny thing on win7: the copy file is 2 bytes longer.

String[] lines;

void get_it () {
  println("read from: "+filename1);
  lines = loadStrings(filename1);
  println("there are " + lines.length + " lines in "+filename1);
  for (int i = 0; i < lines.length; i++) {
    println(lines[i]); // println((i+1)+"_ "+lines[i]);

void save_it() {
  println("save to: "+filename2);
  saveStrings(filename2, lines);
void setup() {

but as i state in the code, i only play processing 3.4 Java mode…
and not “Processing for Android”


Yeah I thought the same but in Processing Android Mode it works this way “loadStrings(“TestStrings.txt”)”, for some reason not sure why? The correct way that we do in Java Mode like this “loadStrings(“data/TestStrings”)”, will give you an error like this.

FATAL EXCEPTION: Animation Thread
Process: processing.test.examplesketch, PID: 5528
java.lang.IllegalArgumentException: File data/TestImage.png contains a path separator
	at android.content.ContextWrapper.getFileStreamPath(
	at processing.core.PSurfaceNone.getFileStreamPath(
	at processing.core.PApplet.sketchPath(
	at processing.core.PApplet.createInputRaw(
	at processing.core.PApplet.createInput(
	at processing.core.PApplet.loadImage(
	at processing.test.examplesketch.ExampleSketch.setup(
	at processing.core.PApplet.handleDraw(
	at processing.core.PSurfaceNone.callDraw(
	at processing.core.PSurfaceNone$

Basically it means that there was a path separator and it couldn’t load the image.

Keep in mind all this that I have only just started getting into Processing Android Mode now. Probably someone more experienced knows away to load up files with path separators. I think it might have something to do with “dataPath”, function call? But don’t trust my “dataPath”, theory.



Also if you put a folder named TestFolder inside of data and put TestImage inside of TestFolder and run this code “loadImage(“TestFolder/TestImage”)” to load up the image it works just fine. It must have something to do with the fact that all files and folders must be inside of data but don’t bet on it.


Thanks for the extra info this will help me in future projects.