Copy link to clipboard
Copied
So I am trying to get the file contents and send them via socket.write().
I am not entirely sure, if I'm doing this right, but I was trying this:
var file = new File( "D:\\test.png" );
var file2 = new File( "D:\\test2.png" );
file.open("r");
file2.open("w");
file2.encoding = file.encoding;
do {
file2.write(file.readch());
}
while ( !file.eof )
test.png exists and test2.png is created from scratch. And the files were not identical in the end. Which means, that getting the file contents with file.readch() or file.read() isn't the right solution. Right?
So, how do I get the file contents in some format, that can be send, and then, probably, rebuilt at the other end?
You could try binary encoding.
var file = new File( "D:\\test.png" ); | |
var file2 = new File( "D:\\test2.png" ); | |
file.open("r"); | |
file.encoding = 'BINARY'; | |
file2.open("w"); | |
file2.encoding = 'BINARY'; | |
do { | |
file2.write(file.readch()); | |
} | |
while ( !file.eof ) ; | |
file.close(); | |
file2.close(); |
Copy link to clipboard
Copied
You could try binary encoding.
var file = new File( "D:\\test.png" ); | |
var file2 = new File( "D:\\test2.png" ); | |
file.open("r"); | |
file.encoding = 'BINARY'; | |
file2.open("w"); | |
file2.encoding = 'BINARY'; | |
do { | |
file2.write(file.readch()); | |
} | |
while ( !file.eof ) ; | |
file.close(); | |
file2.close(); |
Copy link to clipboard
Copied
Using BINARY encoding did the trick. Thanks!
Copy link to clipboard
Copied
var file = new File( "D:\\test.png" );
var file2 = new File( "D:\\test2.png" );
file.copy(file2.absoluteURI);