# Not reading text file for example on website

**URL:** <https://discourse.processing.org/t/not-reading-text-file-for-example-on-website/5750>\
**Category:** Coding Questions\
**Created:** [November 20, 2018, 3:25am UTC](https://discourse.processing.org/t/not-reading-text-file-for-example-on-website/5750 "2018-11-20T03:25:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oz\_joker](https://avatars.discourse-cdn.com/v4/letter/o/9fc29f/32.png) [@Oz\_joker](https://discourse.processing.org/u/Oz_joker)\
**Post date:** [November 20, 2018, 3:25am UTC](https://discourse.processing.org/t/not-reading-text-file-for-example-on-website/5750/1 "2018-11-20T03:25:19Z")

</div>

Hi,

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

[https://processing.org/examples/loadfile1.html](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

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 20, 2018, 4:05am UTC](https://discourse.processing.org/t/not-reading-text-file-for-example-on-website/5750/2 "2018-11-20T04:05:16Z")

</div>

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:

```auto
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

> **[loadStrings() / Reference](https://processing.org/reference/loadStrings_.html)**
>
> Reads the contents of a file and creates a String array of its individual lines. If the name of the file is used as the parameter, as in the above example, the file must be loaded in the sketch's "dat…

also later might use

> **[loadTable() / Reference](https://processing.org/reference/loadTable_.html)**
>
> Reads the contents of a file or URL and creates a Table object with its values. If a file is specified, it must be located in the sketch's "data" folder. The filename parameter can also be a URL to a …

look how powerful that tool is

> **[Table / Reference](https://processing.org/reference/Table.html)**
>
> Table objects store data with multiple rows and columns, much like in a traditional spreadsheet. Tables can be generated from scratch, dynamically, or using data from an existing file. Tables c…

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [November 20, 2018, 4:28am UTC](https://discourse.processing.org/t/not-reading-text-file-for-example-on-website/5750/3 "2018-11-20T04:28:42Z")

</div>

For the location of the file, you can check the comments on [loadStrings()](https://processing.org/reference/loadStrings_.html).

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](https://processing.org/reference/splitTokens_.html)

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

```

Kf

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 20, 2018, 4:32am UTC](https://discourse.processing.org/t/not-reading-text-file-for-example-on-website/5750/4 "2018-11-20T04:32:31Z")

</div>

> [@kfrajer](#):
>
> `String[] pieces = splitTokens(lines[index], "\t ");`

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

> **[splitTokens() / Reference](https://processing.org/reference/splitTokens_.html)**
>
> The splitTokens() function splits a String at one or many character delimiters or "tokens". The delim parameter specifies the character or characters to be used as a boundary.

> 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.
