HELP WITH TRANSFERING FILES BY JAVA

Hi everybody!
I'm making a chat with java (Sever and Client) using socket.
I'd like to know how could I transfer files in binary from this chat.
Could anyone help me??
Thanks in advance!

There's nothing wrong at all about asking questions, or being new to Java. I certainly have a whole world of stuff to learn myself.
Nevertheless, the project you propose is not something a "new user" is typically going to be able to tackle fresh out of the gate. Spend some time with the tutorials, try some stuff out, and when your code breaks, bring it here for review.
Admittedly, I won't be able to help you much with Sockets... :o)

Similar Messages

  • I need help with copying files in java?

    hi, i use the following code sample to copy a directory structure and its files.
    It copy's the directory-structure, but all the files in it have 0kb as size. except one file.
    Here's the code:
    public static void copyDir(String source, String target)
    String [] listing = new String [0];
    FileReader in = null;
    FileWriter out = null;
    String sourcePath = source;
    String targetPath = target;
    // Maakt directory onder target directory
    File f = new File(targetPath);
    f.mkdir();
    // Maakt filelist van bestanden in source-directory
    f = new File(sourcePath);
    listing = f.list();
    for(int i = 0; i < listing.length; i++)
    f = new File(sourcePath + listing);
    if(f.isDirectory())
    copyDir(source + listing[i] + File.separatorChar,
    target + listing[i] + File.separatorChar);
    else
    try
    in = new FileReader(sourcePath + listing[i]);
    out = new FileWriter(targetPath + listing[i]);
    int t;
    while (-1 != (t = in.read()))
    out.write(t);
    try { Thread.sleep(200); } catch (InterruptedException e) { }
    System.out.println("Copied: " + sourcePath + listing[i]);
    catch (Exception e)
    System.out.println(e);

    Here is a quick copy program that works. You'll need to deal with the exception instead of just throwing it though.
    import java.io.*;
    public class Copy
      private static void copy(String source, String target) throws IOException
        // Create directory
        File file=new File(target);
        file.mkdirs();
        // Get contents
        file=new File(source);
        File[] files=file.listFiles();
        // Copy files
        int length;
        byte[] buffer=new byte[1024];
        for(int i=0; i<files.length; i++)
          String destination=target+File.separator+files[ i ].getName();
          if(files[ i ].isDirectory())
            copy(files[ i ].getPath(), destination);
          else
            FileInputStream in=new FileInputStream(files[ i ]);
            FileOutputStream out=new FileOutputStream(destination);
            while((length=in.read(buffer))!=-1)
              out.write(buffer, 0, length);
            in.close();
            out.close();
      public static void main(String[] args) throws IOException
        copy(args[0], args[1]);
    }[\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help With Transferring Files into iTunes Music Folder

    Last year, my computer crashed and I had no backup. I used a program called Sharepod to import all my music from my iPod onto my new computer. Now, all that tranferred music resides in C:\Program Files\Sharepod.
    The songs play just fine out of iTunes, but because I'm a little OCD I'd really like them to be in the iTunes Music folder where they belong. But I've found that when I drag the songs from the Sharepod folder to the iTunes Music folder, I then have to help iTunes "locate" each song one by one. It's very tedious.
    Is there a better way to do this?
    Many thanks!
    Message was edited by: kidsmoke

    Yes. Once songs are in your iTunes library, do not move or rename them in Windows. If you want to get them all in one place, use the iTunes Consolidate command.

  • Need help with transferring files from iPod to iPad mini!

    I just got an iPad mini for Christmas and I would like to know how can I transfer my iPod (2nd gen) files to my new iPad mini?

    See:
    iOS: Transferring information from your current iPhone, iPad, or iPod touch to a new device

  • Help with transferring files from mac to (not my own) HDD; meaning format then copy is impossible

    I need to transfer files and folders from my macbook air to my boss's external HDD but I keep getting error messages. Anyone out there, please help me. Most of the answers here kept saying erase data then copy; not possible for me because this HDD isn't mine. Thanks.

    What is the format of that external HDD?  If it is formatted NTFS, you can read but not write to it.  You would have to install a third party application such as Paragon or Tuxera.
    Ciao.

  • Need help with transferring files

    I am trying to transfer files from my computer (Windows XP) to my S3 with the USB cable. The S3 is showing up as a camera. I have tried both MTP and PTP but it is showing as a camera in both cases. As MTP I do not see any folders, but I do as PTP. I have tried to copy an MP3 file into the music folder but nothing happens. Any suggestions? I am sure I must be doing something wrong. Thanks

    I just tried copying mp3's using both MTP and PTP (on my Windows 7 PC) and both worked.  It may be your XP system that is causing the problem or the cable that you are using.
    See my response in: https://community.verizonwireless.com/message/880150#880150
    about XP and drivers.

  • Help with transferring files that can't be read

    Recently lightroom or my computer has been acting up. My files can't be read through my camera from a CF card to an external drive of mine. Has anyone else had this problem?

    Maybe you could give us more details, like the exact error message you are getting, and exactly what you are doing and what happens. What type of files (JPG, RAW, other) and what camera? What operating system?
    It could be any one a gazillion things (well, it could be any one of a dozen things) including hardware, permissions, wrong version of LR for your camera, etc.

  • Help with transferring files from Windows to MacBook Pro

    Just got a new MacBook Pro and need to transfer files from a very old Windows operating machine. Have the Seagate Slim portable drive.  I downloaded the online software to format it for the windows files (taking 4 hours).  Now, I'm told it will not work on the Apple product.  Has anyone used this and had success? Or is there an easier way?

    Hello CharliePaints,
    Thank you for using Apple Support Communities.
    For more information, take a look at:
    Switch Basics: Migrate your Windows files to your Mac
    http://support.apple.com/kb/ht2518
    Transfer information from your PC over your wired or wireless network
    To move files using Migration Assistant to your Mac from your PC, use these steps.
    Have a nice day,
    Mario

  • Help with transferring files from mac to another hard drive...

    my mac wont let me transfer files from mac hard drive to a external hard drive, i've done it before, but suddenly it wont allow this? what could it be?

    Also Its my mums computer, i'm trying to fix it for her, she's running osx 10.10.2

  • Can some help with CR2 files ,Ican`t see CR2 files in adobe bridge

    can some help with CR2 files ,I can`t see CR2 files in adobe bridge when I open Adobe Photoshop cs5- help- about plugins- no camera raw plugins. When i go Edit- preference and click on camera raw  shows message that Adobe camera raw plugin cannot be found

    That's strage. Seems that the Camera Raw.8bi file has been moved to different location or has gone corrupt. By any chance did you try to move the camera raw plugin to a custom location?
    Go To "C:\Program Files (x86)\Common Files\Adobe\Plug-Ins\CS5\File Formats" and look for Camera Raw.8bi file.
    If you have that file there, try to download the updated camera raw plugin from the below location.
    http://www.adobe.com/support/downloads/thankyou.jsp?ftpID=5371&fileID=5001
    In case  you ae not able to locate the Camera Raw.8bi file on the above location, then i think you need to re-install PS CS5.
    [Moving the discussion to Photoshop General Discussions Forum]

  • Help with add file name problem with Photoshop CS4

    Frustrating problem: Help with add file name problem with Photoshop CS4. What happens is this. When I am in PS CS4 or CS3 and run the following script it runs fine. When I am in Bridge and go to tools/photoshop/batch and run the same script it runs until it wants interaction with preference.rulerunits. How do I get it to quit doing this so I can run in batch mode? Any help is appreciated. HLower
    Script follows:
    // this script is another variation of the script addTimeStamp.js that is installed with PS7
    //Check if a document is open
    if ( documents.length > 0 )
    var originalRulerUnits = preferences.rulerUnits;
    preferences.rulerUnits = Units.INCHES;
    try
    var docRef = activeDocument;
    // Create a text layer at the front
    var myLayerRef = docRef.artLayers.add();
    myLayerRef.kind = LayerKind.TEXT;
    myLayerRef.name = "Filename";
    var myTextRef = myLayerRef.textItem;
    //Set your parameters below this line
    //If you wish to show the file extension, change the n to y in the line below, if not use n.
    var ShowExtension = "n";
    // Insert any text to appear before the filename, such as your name and copyright info between the quotes.
    //If you do not want extra text, delete between the quotes (but leave the quotes in).
    var TextBefore = "Lower© ";
    // Insert any text to appear after the filename between the quotes.
    //If you do not want extra text, delete between the quotes (but leave the quotes in).
    var TextAfter = " ";
    // Set font size in Points
    myTextRef.size = 10;
    //Set font - use GetFontName.jsx to get exact name
    myTextRef.font = "Arial";
    //Set text colour in RGB values
    var newColor = new SolidColor();
    newColor.rgb.red = 0;
    newColor.rgb.green = 0;
    newColor.rgb.blue = 0;
    myTextRef.color = newColor;
    // Set the position of the text - percentages from left first, then from top.
    myTextRef.position = new Array( 10, 99);
    // Set the Blend Mode of the Text Layer. The name must be in CAPITALS - ie change NORMAL to DIFFERENCE.
    myLayerRef.blendMode = BlendMode.NORMAL;
    // select opacity in percentage
    myLayerRef.opacity = 100;
    // The following code strips the extension and writes tha text layer. fname = file name only
    di=(docRef.name).indexOf(".");
    fname = (docRef.name).substr(0, di);
    //use extension if set
    if ( ShowExtension == "y" )
    fname = docRef.name
    myTextRef.contents = TextBefore + " " + fname + " " + TextAfter;
    catch( e )
    // An error occurred. Restore ruler units, then propagate the error back
    // to the user
    preferences.rulerUnits = originalRulerUnits;
    throw e;
    // Everything went Ok. Restore ruler units
    preferences.rulerUnits = originalRulerUnits;
    else
    alert( "You must have a document open to add the filename!" );

    you might want to try the scripting forum howard:
    http://www.adobeforums.com/webx?13@@.ef7f2cb

  • How to embedd Fusion Charts with XML files in java? Please help me.......

    Hi....iam trying to display Fusion Charts. Iam using Hibernate to bring data from database.
    what i want to do is to put data on xml, once my xml gets dynamic data from database, then it will be clubbed with swf files(fusion charts) to show graphs such as line charts,etc.
    I know wat to do. But big Question is how to do ?
    am i right in my Logic ?

    Hi
    Your approach seems to be right.
    Get the data using hibernate into your struts action ( if you are using struts ).
    Set the xml and any other property as request attribute.
    Embed the chart in JSP, by including FusionChartsRenderer.jsp ( found in download package ) and passing xml ( got from request attribute ) and other values as parameters to it.
    Please check the FusionCharts forum for some discussions on Struts, JSP implementation. ( /forum - you could use the search feature available there )
    Please refer to the documentation of FusionCharts as well. ( /docs )
    Hope this helps!
    Srividya

  • Need help with batch file for javac.exe and java.exe

    I have this in my batch file:
    c:\jdk1.3.1_05\bin\javac
    What symbol do I need to be able to run this from cprompt with any file following it

    Thanks could remember that for nothing

  • Need help with connecting file inputs to arrays

    In this assignment I have a program that will do the following: display a list of names inputed by the user in reverse order, display any names that begin with M or m, and display any names with 5 or more letters. This is all done with arrays.
    That was the fun part. The next part requires me to take the names from a Notepad file, them through the arrays and then output them to a second Notepad file.
    Here is the original program: (view in full screen so that the code doesn't get jumbled)
    import java.io.*;       //Imports the Java library
    class progB                    //Defines class
        public static void main (String[] arguments) throws IOException
            BufferedReader keyboard;                                  //<-
            InputStreamReader reader;                                 //  Allows the program to
            reader = new InputStreamReader (System.in);               //  read the the keyboard
            keyboard = new BufferedReader (reader);                  //<-
            String name;                 //Assigns the name variable which will be parsed into...
            int newnames;               //...the integer variable for the amount of names.
            int order = 0;              //The integer variable that will be used to set the array size
            String[] array;             //Dynamic array (empty)
            System.out.println (" How many names do you want to input?");   //This will get the number that will later define the array
            name = keyboard.readLine ();
            newnames = Integer.parseInt (name);                                         // Converts the String into the Integer variable
            array = new String [newnames];                                               //This defines the size of the array
            DataInput Imp = new DataInputStream (System.in);       //Allows data to be input into the array
            String temp;                                       
            int length;                                                                  //Defines the length of the array for a loop later on
                for (order = 0 ; order < newnames ; order++)                                //<-
                {                                                                           //  Takes the inputed names and
                    System.out.println (" Please input name ");                            //  gives them a number according to
                    temp = keyboard.readLine ();                                           //  the order they were inputed in
                    array [order] = temp;                                                  //<-
                for (order = newnames - 1 ; order >= 0 ; order--)                                //<-
                {                                                                                //  Outputs the names in the reverse 
                    System.out.print (" \n ");                                                   //  order that they were inputed
                    System.out.println (" Name " + order + " is " + array [order]);             //<-
                for (order = 0 ; order < newnames ; order++)                                  //<-
                    if (array [order].startsWith ("M") || array [order].startsWith ("m"))     //  Finds and outputs any and all
                    {                                                                         //  names that begin with M or m
                        System.out.print (" \n ");                                            //
                        System.out.println (array [order] + (" starts with M or m"));         //
                    }                                                                         //<-
                for (order = 0 ; order < newnames ; order++)                                            //<-
                    length = array [order].length ();                                                   //
                    if (length >= 5)                                                                    //  Finds and outputs names
                    {                                                                                  //  with 5 or more letters
                        System.out.print (" \n ");                                                      //
                        System.out.println ("Name " + array [order] + " have 5 or more letters ");      //<-
    }The notepad file contains the following names:
    jim
    laruie
    tim
    timothy
    manny
    joseph
    matty
    amanda
    I have tried various methods but the one thing that really gets me is the fact that i can't find a way to connect the names to the arrays. Opening the file with FileInputStream is easy enough but using the names and then outputing them is quite hard. (unless i'm thinking too hard and there really is a simple method)

    By "connect", do you just mean you want to put the names into an array?
    array[0] = "jim"
    array[1] = "laruie"
    and so on?
    That shouldn't be difficult at all, provided you know how to open a file for reading, and how to read a line of text from it. You can just read the line of text, put it in the array position you want, until the file is exhausted. Then open a file for writing, loop through the array, and write a line.
    What part of all that do you need help with?

  • Help with AudioClip files

    Hi, i got a problem with using AudioClip classes with jars, my application works normally when i use it with the command prompt, but it doesn't with a jar file, i specified the classpath in the manifest file and the main class as well, but this line of code throws me a NullPointerException:
    song = Applet.newAudioClip(getClass().getResource("./50_cent_-_candy_shop.mid"));The weird thing is that the images work, but not the file.
    Help is appreciated.

    Wow, when i use it in the command line it gives me the right path, but when i use it on the jar file it returns null.
    C:\Java\Programas\Hangman>java Play
    file:/C:/Java/Programas/Hangman/
    C:\Java\Programas\Hangman>jar -cfm Hangman.jar Manifest.mf *.class images *.mid
    C:\Java\Programas\Hangman>java -jar Hangman.jar
    Exception in thread "main" java.lang.NullPointerException
    at HangmanGUI.setEvents(HangmanGUI.java:223)
    at HangmanGUI.setComponents(HangmanGUI.java:144)
    at HangmanGUI.<init>(HangmanGUI.java:98)
    at Play.main(Play.java:5)

Maybe you are looking for