How do I transfer files verbatim across a socket connection?

So, I've got this socket connection running between two computers. I want one computer to take a file (C:\SourceFile.doc for example) and transfer it verbatim over an Internet connection to another computer (C:\DestFile.doc for example). By verbatim, I mean bit for bit, no changes to the format. It would seem that a filereader/filewriter system would work, and it does fine for .txt or plain files, but if I try to do something fancy, like a Microsoft word document (.doc) it doesn't work. Specifically, it saves a bunch of garbage at the begging and end of the file. How do I correct this?
From my file transmitter:
out.println("Prepare for Text File");
FileReader localin = new FileReader(file);
int l=0;
while((l=localin.read())!=-1)
     //System.out.print((char)l);
     out.print((char)l);
localin.close();
out.println("End Of File");
From my file reciever
if(line.equals("Prepare for Text File"))
     System.out.println("ready for text");               if(fileChooser.showSaveDialog(RadioComReciever.this)==JFileChooser.APPROVE_OPTION)
File localFile=fileChooser.getSelectedFile();
          FileWriter localout = new FileWriter(localFile);
          line=in.readLine();
          while(!line.equals("End Of File"))
               for(int i=0;i<line.length();i++)
               {                                                                 localout.write((byte)line.charAt(i));
               localout.write('\n');
               System.out.println();
               line=in.readLine();
          localout.close();
Thanks for any help!

But my program is already accessing text from a
socket connection. Is there a way to transfer things
over sockets other than text?Yes. Everything that goes over a socket connection is bytes. Certainly you can transfer text, because it can be represented in bytes, but not all files are text. So just send the bytes as is.
Don't get me wrong, I'm thankful for you help, I just
thought scokets mostly transfered just text. Am I
wrong?I don't have any statistics on how much Internet traffic is text. But 100% of it is bytes. Just send the bytes as is.
And is it just me, or is the documentation on File
I/O provided by Sun somewhat lacking?It isn't the job of the documentation to explain basic Java concepts like the difference between byte and char. That's the job of the tutorials. Like the Java I/O tutorial.

Similar Messages

  • How can I transfer files from one external HD (WD My Passport) to another external HD (Seagate Backup Plus)?  WD drive was improperly ejected and Finder no longer recognizes it.  Tried fixing with Disk Utility but failed.

    How can I transfer files from one external HD (WD My Passport 2T) to another external HD (Seagate Backup Plus 2T)?  WD drive was improperly ejected (although we did tell it to eject) and now Finder no longer recognizes it.   Using MacBook Pro and I just upgraded to Yosemite before this happened. Was told at Apple Store to use Disk Utility to repartition, but it failed.  It says to backup files and restore.  But how do I backup files?  Or would appreciate any other suggestions to repair drive.

    You may drag & drop between external hds. 
    Should you run into trouble.
    Take the exernal drive appart.  Take out the harddrive.  Try reading the data via a usb adapter. Put a household finan on the hd.
    http://www.cablewholesale.com/products/usb-firewire/usb-2.0-products/product-40u   2-01000.php?utm_source=Nextag&utm_medium=cpc&zmam=54972865&zmas=1&zmac=4&zmap=4 4 77

  • How do I transfer files from one computer to another without using cables??

    How do I transfer files from one computer to another without using cables?

    Wifi network
    Email
    Thumb Drive
    Online storage such as, iCloud Google Docs, SkyDrive, etc.

  • How can i transfer files from adobe reader to my kobo e-book

    how can i transfer files from adobe reader to my kobo e-book??

    I think you should ask in the Digital Editions forum,
    http://forums.adobe.com/community/adobe_digital_editions
    This is the Reader one.

  • How can I transfer files from my computer to my I pad ?

    How can I transfer files from my computer to my I Pad?

    Try a conduit such as Dropbox.
    Goodreader or Documents to Go also have helper apps that allow transfers.
    Goodreader is particularly good in that it has a integal file tree and you can mount your computers harddrive and navigate directly on your ipad.
    Use the open with to view/move files into other apps.

  • How can I transfer files from my mac to my iPad, e.g., mp4 files.  Do I have to use iTunes?

    How can I transfer files from my mac to my iPad in an easier way?  I'd like to put some movies on, and I can use iTunes, but is there another way?  I have transferred epub books using Dropbox.  Movies eat up a lot of dropbox space and the iPad has trouble getting them.

    USB disk. You still have to go through iTunes.
    Connect device to computer/mac
    Select your device in iTunes menu.
    Apps...
    At thebottom of the page you will see the app.
    Select it and the Add for windows and + for mac
    Hope that helped.
    In the long run there is no way to access or uplood data on your device without iTunes unless you JailBrake....

  • How do i transfer files from 1 profile to another

    How do i transfer files from 1 user profile to another

    Choose Go to Folder from the Finder's Go menu, provide /Users/Shared/ as the path, drag them to it, and if desired, from there into the second account's home folder.
    (111041)

  • How can i transfer files from iphone to iphone through bluetooth

    how can i transfer files in iphone 4 through bluetooth options. Do i need to install any application for that ?

    Here is one such application that will do the job.
    Bluetooth-U
    B-rock

  • How can I transfer files from Apps to the PC in iTunes 11.1.3.8

    How can I transfer files from Apps to thr PA in iTunes 11.1.3.8
    (App :eBooks from Bluefire Reader)

    Connect the device to iTunes.
    Select the Apps tab.
    Select the apps desired to sync.
    Sync.
    iTunes remembers sync settings per device.

  • How can I transfer files from my 2007 iMac to my new MacBook Pro?

    How can I transfer files from my 2007 iMac to my new MacBook Pro?  It cannot be does over wi-fi as my old computer is too old.  Please advise!

    Use a Thunderbolt to Ethernet or FireWire adapter.
    (95019)

  • How do i transfer file from my pc to my mac

    How do i transfer files from my pc to my new i mac

    I am struggling to transfer files over to my new Mac and the data migration at the store failed.  They didn't explain why - just told me I had to do it myself manually.
    I put all the files (lots of work stuff!) on my external hard drive, but the Mac isn't even showing these files in the library when I connect the external hard drive.  The Office Suite opens programs like Word, so it seems to have loaded properly.
    Ideas?

  • I have deleted my private folder and do not have enough space to reinstall my operating system. How can i transfer files from my hard drive to an USB drive to free up space when the operating system isn't working. or do i need to erase disk?

    i have deleted my private folder and do not have enough space to reinstall my operating system. How can i transfer files from my hard drive to an USB drive to free up space when the operating system isn't working. or do i need to erase disk through disk utilities without erasing data (but will it delete my programs such as photoshop, office, creative suite?

    Connect the computer to another Mac and put it in FireWire Target Disk mode, or use the Disk Utility to clone the drive or image specific folders with the USB drive as the target. After you've copied off everything you want, you'll likely need to erase the drive and reinstall the applications.
    (69695)

  • How do i transfer files from my external hard drive to my new macbook pro?

    how do i transfer files from my external hard drive to my new macbook pro?

    Hi niel, when I open my hard drive in my mac, I cannot find any files in there. I guess its not reading my hard drive.

  • How do I transfer files from my old iMac to my new Pro laptop?

    How do I transfer files from my old iMac to my new Pro laptop?

    If you can get both computers on the Internet at the same time without re-cabling, you have the connection infrastructure needed to enable file sharing and share those files.
    That said, many users find it easier to use FireWire Target Disk mode to treat the old computer as a big Hard drive, and just drag and drop the files, or use Migration Assistant or Setup Assistent.
    There is a really good guide here:
    http://pondini.org/OSX/Setup.html

  • How do i transfer files from my old pc to my new i mac

    How do i transfer files from my old pc to my new i mac

    See Here...
    Setting-up a new Mac from an old one, its backups, or a PC
    Using Migration Assistant on Lion

Maybe you are looking for

  • How to adjust for distorted colors printing on HP 8500 A909g.

    In regard to HP All In One 8500 A909g.  Photos look great on computer screen but print with an overall red hue.  I can eventually adjust the color to get a good print but it wastes a lot of ink getting there.  Why doesn't my printer print the colors

  • Zen X-Fi Style crashes my PC

    Hi. My new Zen X-Fi Style mp3-player makes my computer freeze up after a certain amount of time. It can be from 5 to 5 minutes, but it crashes nonetheless. I can only reboot the computer after this happens. I have thus far tried to use an external US

  • Delete item to wastebasket get missing user error

    When I tried to delete a document from "my portfolio" in portal to my waste basket, I got error message "missing user". By checking the SAP log trace file, it showed "Cannot instantiate user <anonymous>". Our Portal (Netweaver 7.0) is SSO to LDAP, an

  • POS inbound Price calculation

    Hi SDN Guys, I need to do price calculation for the weighted artivles EAN starting with 21*. As per my knowledge the sap does some calculation ;ie weight /sap standard price. but we need to conisder the Weight/SAP standardprice(per plant) { I think w

  • T410 slow wireless speeds

    We recently acquired two refurbished T410's - both of these laptops have extremely slow wireless speeds (slow or no page loads) and it seems that they periodically disconnect from the wireless connection for short periods of time. I have these laptop