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

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