[SOLVED] Path to file in createWriter?

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.

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.

2 Likes

i see here ( win 7 64b )

so i try:

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

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

good too.


also see


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

1 Like

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.

-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

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.

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:

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

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


firewall warning JAVA ! see the one from inside processing is used:
but a example is running already

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.

1 Like

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

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.

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

Have you tried the following in your original code?

output = createWriter("C:\\Users\\John\\Documents\\Processing\\sample_data");
3 Likes

^^^ 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)

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

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

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.

3 Likes

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: \\
Reference / Processing.org

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