Not reading text file for example on website

Hi,

I’m trying to get this simple example to work from your website:

https://processing.org/examples/loadfile1.html

I’ve made a text file called positions.txt, and followed the instructions on the website, "Loads a text file that contains two numbers separated by a tab (’\t’) ".

When I run the script, it’s opening the txt file I’ve made, but I don’t think I’ve got the formatting right for the pairs of numbers it reads in. It seems so simple, I don’t know what I’m doing wrong.

Could you please provide me with the example text file this script is using?

Thanks,

Oz_joker

you have processing 3.4 installed? pls. find:

YOUR_DRIVE_:\YOUR_INSTALL_PATH\processing-3.4\modes\java\examples\Topics\File IO\LoadFile1\data\positions.txt

like:

70	35
69	35 

need to be a real Tab, not a Blank

but why not change all that to a ?better? standard:
call the file
positions.csv
and use a “,” as separator ( in the file and for the split )

and make the file by some spreadsheet tools ( like excel )
and from there use [save as][.csv]

and instead

also later might use

look how powerful that tool is

1 Like

For the location of the file, you can check the comments on loadStrings().

If the problem is that you are not using real tabs but spaces to separate the values on a line, you can try this alternative for data/token splitting: splitTokens

String[] pieces = splitTokens(lines[index], "\t ");

Kf

splitTokens() already uses constant WHITESPACE by default. So it can be shortened like this: :smile_cat:
String[] pieces = splitTokens(lines[index]);

If no delim characters are specified, any whitespace character is used to split. Whitespace characters include tab (\t), line feed (\n), carriage return (\r), form feed (\f), and space.

1 Like