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 EZ-B v4

ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

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

PRO
USA
#2  

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

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.

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 \

PRO
USA
#5  

Thank you.  Learning as i go.