# \[SOLVED\] Path to file in createWriter?

**URL:** <https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940>\
**Category:** Coding Questions\
**Created:** [March 4, 2019, 6:53pm UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940 "2019-03-04T18:53:14Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![WyattStorch](https://avatars.discourse-cdn.com/v4/letter/w/848f3c/32.png) [@WyattStorch](https://discourse.processing.org/u/WyattStorch)\
**Post date:** [March 4, 2019, 6:53pm UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/1 "2019-03-04T18:53:14Z")

</div>

Why am I getting this error and how do I fix it? I spent hours searching and am having little luck except discovering that file I/O is, ummm, problematic for beginners in Java.

I am experimenting with Processing 3.5.3 in Windows 7 64 bit and for now, targeting similar systems.

```auto
PrintWriter output;

size (100,100);
output = createWriter("C:\Users\John\Documents\Processing\sample_data");//Any windows path!!
output.println("a, b, c,");
output.flush();
output.close();
exit();

```

The error is; _processing.app.SketchException: Not expecting symbol ‘U’, which is LATIN CAPITAL LETTER U._

I suspect the path is not expected to be part of the file name maybe. Edit: The example sketch for createWriter obviously works if only the file name is included, it writes the file in the same subdirectory as the sketch. I can’t use it like that in the application I am working on.

Edit: If you’re here for this kind of problem, skip to the bottom. The TLDR is there.

---

<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:** [March 5, 2019, 1:44am UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/2 "2019-03-05T01:44:07Z")

</div>

> [@WyattStorch](#):
>
> output = createWriter(“C:\Users\John\Documents\Processing\sample\_data”);

i see here ( win 7 64b )

 ![snap_0041](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/cddb92a0f4002ae17f0e33397147524beea24867.jpeg)

so i try:

```auto
PrintWriter output;
size (100,100);
output = createWriter("C:/Users/user/Downloads/sample_data"); //Any windows path!!
output.println("a, b, c,");
output.flush();
output.close();
exit();

```

and it works.

check linux Raspbian

```auto
output = createWriter("/home/pi/Downloads/sample_data");

```

good too.

* * *

also see

 ![snap_0042](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7210f0dcf77d23f0c6dbf24d5bce756c0f47b143.jpeg)

* * *

but for understand the error i see ( my first picture )  
it is a JAVA STRING thing ( what allows \n == linefeed )  
so it will not allow windows path string???

funny is only that you see a different error  
even we both use same windows and processing

---

<div class="post-metadata">

**Author:** ![WyattStorch](https://avatars.discourse-cdn.com/v4/letter/w/848f3c/32.png) [@WyattStorch](https://discourse.processing.org/u/WyattStorch)\
**Post date:** [March 5, 2019, 4:48am UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/3 "2019-03-05T04:48:25Z")

</div>

kll,

Thank you for your reply. You jogged my memory and it reminds me I gave you bad information.

I wrote “Win 7 64 bit” and that may be wrong. This system is Win 7 64 bit but – I was trying to use an old sketch, really old, so I uninstalled Processing and installed the 32 bit version to get something or other working. (I’ve since abandoned that approach.) So my path environmental variable to java is “PATH=C:\Program Files (x86)\Common Files\Oracle\Java\javapath;” in the path statement, and on disk there is “C:\Program Files (x86)\Java\jre1.8.0\_201\bin”.

Sigh. I need to uninstall and start over with the Win64 distribution, I think.

Edit: It appears I’m using 64 bit Processing but with 32 bit Java. LOL.

---

<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:** [March 5, 2019, 6:53am UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/4 "2019-03-05T06:53:30Z")

</div>

-a- for the createWriter question  
you used \ got error  
i used / and it works

-b- for the version thing,  
on windows 7 64bit you can download / unzip processing 32 bit or 64 bit  
until now i could not make out the difference (speed?)

-c- for the used JAVA, each comes with a JAVA included  
you could even in

- windows / control panel / java /
- tab / java / view /
- find ( processing )  
 ![snap_0046](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e293a719bb557c004b8c437e51725b18a1ed7e6c.jpeg)  
( but that is not required )

so as it just works, i not understand what was not running,  
anyhow i not see the relation to the  
createWriter(filenamestringwithpath);  
question.  
pls. explain again.

---

<div class="post-metadata">

**Author:** ![WyattStorch](https://avatars.discourse-cdn.com/v4/letter/w/848f3c/32.png) [@WyattStorch](https://discourse.processing.org/u/WyattStorch)\
**Post date:** [March 5, 2019, 7:38am UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/5 "2019-03-05T07:38:42Z")

</div>

> [@kll](#):
>
> set PATH=PATH;C:\Program Files\Java\JDK1.6.20\bin

The above path and file do not actually exist on my system. So now I am trying to figure out if I should download and install that. If I can find it.

Edit:

 ![snip2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a44ab4e7874fd4a81bd92187f5fff55d25458910.jpeg)

I’ll be back in a few hours. Thanks so much for your help.

---

<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:** [March 5, 2019, 8:58am UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/6 "2019-03-05T08:58:09Z")

</div>

no, sorry, that was not from my computer, from a old documentation…  
sorry that it confused you, my mistake.  
the java on your system looks ok.

again look my picture, i also have the 1.89.0.201 on my system…  
anyhow the one from the processing is used…

! to be absolutely certain about this  
i used a old hard disk with win7 32bit:  
– deleted all processing ( unzips )  
– deleted all sketchdir  
– deleted the c:\users\user\AppData\Roaming\Processing  
( where also the preferences.txt file is )

and  
ControlPanel/Programs and Features /  
uninstall JAVA 8

processing 3.5.3 32bit  
download unzip  
start processing.exe

 ![snap-095](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1667bbbe91e1958684c6aaa1189bab0c9c1143f7.jpeg)  
firewall warning JAVA ! see the one from inside processing is used:  
but a example is running already  
 ![snap-096](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0355d76058f3783111e9de848b5d52bcf7db8096.jpeg)  
so again, processing windows comes with JAVA and not need  
a java on windows system,  
also, i made that mistake already, i used the CMD terminal window and run

> JAVA -version  
> you get the one from system, so that is not related to processing.

to complete my system i reinstall JRE 8 again.

 ![snap-097](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4e162516e56ad62e2fe27cc6cd7a3034c4c0aebe.jpeg)

---

<div class="post-metadata">

**Author:** ![WyattStorch](https://avatars.discourse-cdn.com/v4/letter/w/848f3c/32.png) [@WyattStorch](https://discourse.processing.org/u/WyattStorch)\
**Post date:** [March 6, 2019, 2:03am UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/7 "2019-03-06T02:03:59Z")

</div>

Thanks, kll.

I’ve spent a lot of time trying to find out if I’ve got the wrong Java, LOL.

And now I’m just confused. I don’t know if I can use the latest version of Java, I don’t know if installing it will break this program. I don’t know why I can’t specify the path with that command. I don’t know if I have to use a different command to be able to specify the path. I’ve done file operations before, using other languages. I don’t know why they have to be so bureaucratic in Java. And, I don’t know why the sketch works on your system but not mine.

I really don’t want to change languages again. LOL

---

<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:** [March 6, 2019, 2:09am UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/8 "2019-03-06T02:09:06Z")

</div>

pls see my just updated post above  
the java installed on the windows is not relevant as processing for windows comes with java

so back to the sketch question, pls post the sketch code and  
the error ( or a picture of the error ) again.

---

<div class="post-metadata">

**Author:** ![FSXAC](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fsxac/32/3995_2.png) [@FSXAC](https://discourse.processing.org/u/FSXAC)\
**Post date:** [March 6, 2019, 2:10am UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/9 "2019-03-06T02:10:13Z")

</div>

Isn’t this because the character `\` is an escape character when used in strings?

Have you tried the following in your original code?

```auto
output = createWriter("C:\\Users\\John\\Documents\\Processing\\sample_data");
```

---

<div class="post-metadata">

**Author:** ![WyattStorch](https://avatars.discourse-cdn.com/v4/letter/w/848f3c/32.png) [@WyattStorch](https://discourse.processing.org/u/WyattStorch)\
**Post date:** [March 6, 2019, 2:11am UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/10 "2019-03-06T02:11:34Z")

</div>

^^^ I’ll try this.

kll:  
Thank you so much for doing all that. I’m sure I don’t deserve it.

Edit: IT WORKS! (Except it now says couldn’t create a Writer for it.)  
Edit2: Fixed it by putting a file suffix on the filename. (.txt)

---

<div class="post-metadata">

**Author:** ![WyattStorch](https://avatars.discourse-cdn.com/v4/letter/w/848f3c/32.png) [@WyattStorch](https://discourse.processing.org/u/WyattStorch)\
**Post date:** [March 6, 2019, 2:17am UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/11 "2019-03-06T02:17:34Z")

</div>

Thank you kll and FSXAC for your help. I owe you both.

---

<div class="post-metadata">

**Author:** ![FSXAC](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fsxac/32/3995_2.png) [@FSXAC](https://discourse.processing.org/u/FSXAC)\
**Post date:** [March 6, 2019, 2:25am UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/12 "2019-03-06T02:25:53Z")

</div>

No problem. Just be extra careful where there are `\` in strings.

---

<div class="post-metadata">

**Author:** ![WyattStorch](https://avatars.discourse-cdn.com/v4/letter/w/848f3c/32.png) [@WyattStorch](https://discourse.processing.org/u/WyattStorch)\
**Post date:** [March 6, 2019, 4:00am UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/13 "2019-03-06T04:00:26Z")

</div>

The TLDR is:

The backslash happens to be an escape character for special characters in Processing.

So double-escape them when intending to actually use the backslash, like in a Windows pathname. “C:\\directory\\file.ext”. And in this instance at least, the file extension is necessary.

Thanks again for the help.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [March 7, 2019, 10:56pm UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/14 "2019-03-07T22:56:51Z")

</div>

> [@WyattStorch](#):
>
> The backslash happens to be an escape character for special characters in Processing.

That is correct – it gets this from Java, and is part of string handling – for example, it allows you to include a `"` character in a String. From the reference:

> Because backslash is the escape character, to include a single backslash within a String, you must use two consecutive backslashes, as in: **\\**  
> [String / Reference / Processing.org](https://processing.org/reference/String.html)

---

<div class="post-metadata">

**Author:** ![WyattStorch](https://avatars.discourse-cdn.com/v4/letter/w/848f3c/32.png) [@WyattStorch](https://discourse.processing.org/u/WyattStorch)\
**Post date:** [March 9, 2019, 1:22am UTC](https://discourse.processing.org/t/solved-path-to-file-in-createwriter/8940/15 "2019-03-09T01:22:08Z")

</div>

Thanks, Jeremy. " it gets this from Java, and is part of string handling"  
Good to know.
