Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Copy a file in java

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Copy a file in java

    Hey, I'm trying to copy a exe file from one location to another. It seems simple, but I have failed to find anything about it besides coping the contents in txt files, but that does nothing for executable.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: Copy a file in java

    Show what you've tried.

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Copy a file in java

    Well, I don't even know where to start, all the examples I've seen gone like this

    private static void copyFileUsingFileStreams(File source, File dest)
    		throws IOException {
    	InputStream input = null;
    	OutputStream output = null;
    	try {
    		input = new FileInputStream(source);
    		output = new FileOutputStream(dest);
    		byte[] buf = new byte[1024];
    		int bytesRead;
    		while ((bytesRead = input.read(buf)) > 0) {
    			output.write(buf, 0, bytesRead);
    		}
    	} finally {
    		input.close();
    		output.close();
    	}
    }


    --- Update ---

    Well, Now I feel stupid, it was just a typo on my end

  4. #4
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    73
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: Copy a file in java

    And if you use Java 7: Files (Java Platform SE 7 )

Similar Threads

  1. why copy constructor in java and what is use
    By kundanranjan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 24th, 2014, 04:46 AM
  2. Replies: 1
    Last Post: January 12th, 2014, 03:58 AM
  3. Copy the folder with Java
    By teymoorei in forum Java Theory & Questions
    Replies: 3
    Last Post: June 17th, 2013, 10:03 AM
  4. How do I copy a simple text-file to a new text-file?
    By get703 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: December 5th, 2012, 09:59 PM
  5. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 PM

Tags for this Thread