• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

File copying and getting file contents

Explorer ,
Feb 16, 2015 Feb 16, 2015

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?

TOPICS
Actions and scripting

Views

353

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Feb 16, 2015 Feb 16, 2015

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

Votes

Translate

Translate
Adobe
Enthusiast ,
Feb 16, 2015 Feb 16, 2015

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 06, 2015 Mar 06, 2015

Copy link to clipboard

Copied

LATEST

Using BINARY encoding did the trick. Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Feb 16, 2015 Feb 16, 2015

Copy link to clipboard

Copied

var file = new File( "D:\\test.png" ); 

var file2 = new File( "D:\\test2.png" ); 

file.copy(file2.absoluteURI);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines