Asked
Resolved Resolved by DJ Sures!

Reading And Writing Files In Java

I am not a Java expert.  Can someone post an example of how to open/write and open/read a file on my local computer using the ARC Java Script editor?

Thank you very much.



Related Hardware (view all EZB hardware)
EZ-B V4 by EZ-Robot
EZ-B v4/2 robot controller: dual Cortex ARM, Wi-Fi, audio/video, 24 servo/digital ports, I2C/UART, camera and Synthiam ARC control for custom robots
Wi-Fi / USB
Servos 24
Camera
Audio
UART 3
I2C
ADC 8
Digital 24

ARC Pro

Upgrade to ARC Pro

With ARC Pro, your robot is not just a machine; it's your creative partner in the journey of technological exploration.

Author Avatar
PRO
Synthiam
#1   — Edited

I believe you mean JavaScript. Synthiam does not support anything Java related. There's a big difference (not only in the spelling) of Java and JavaScript:)

Use the File class to write files. Type File and hit . and all of the related stuff will appear.

User-inserted image


var filename = "C:\\temp\\testfile.txt";

File.appendString(filename, "Some data to write");

var x = File.readLine(filename);

File.readClose(filename);

print(x);
Author Avatar
PRO
USA
#2  

Thanks.  No where could if find i needed a double \ in the file path.

Author Avatar
PRO
Synthiam
#3  

In programming, a \n in a string means new line. or \t means tab. There's a whole list of "escape characters" for strings.

Author Avatar
PRO
Synthiam
#4  

I found this for ya on google

JavaScript String Escape / Unescape

Escapes or unescapes a JavaScript string removing traces of offending characters that could prevent interpretation.

The following characters are reserved in JavaScript and must be properly escaped to be used in strings:

Horizontal Tab is replaced with \t Vertical Tab is replaced with \v Nul char is replaced with \0 Backspace is replaced with \b Form feed is replaced with \f Newline is replaced with \n Carriage return is replaced with \r Single quote is replaced with ' Double quote is replaced with " Backslash is replaced with \

Author Avatar
PRO
USA
#5  

Thank you.  Learning as i go.