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 2 of 2

Thread: I need help for this copy byte code ...

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need help for this copy byte code ...

    hi guys I need this code to ask d user to ENTER the FILE Name to be copied and what's the name of the new file where it will be copied.Thanks :]


    import java.io.File;
    import java.io.IOException;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;

    public class copybytes {

    public void copyFile(String fromFile, String toFile) {

    FileInputStream fin = null;
    FileOutputStream fout = null;

    try {

    File file = new File(fromFile);
    if (!file.exists() || !file.isFile()) {
    System.out.println("Could not perform operation, file doesn\'t exist");
    return;
    }

    fin = new FileInputStream(file);
    fout = new FileOutputStream(toFile);


    byte[] buffer = new byte[1024];
    int bytesRead;
    while ((bytesRead = fin.read(buffer)) > 0) {
    fout.write(buffer, 0, bytesRead);
    }
    }
    catch (IOException ioe) {
    ioe.printStackTrace();
    }
    finally {
    try {
    if (fin != null)
    fin.close();
    if (fout != null)
    fout.close();
    }
    catch (IOException ioe) {
    ioe.printStackTrace();
    }
    }
    }

    public static void main(String[] args) {
    copybytes fileutil = new copybytes();
    fileutil.copyFile("F:\\\\rica.txt",
    "F:\\\\muah.txt");
    }
    }

    this code is not mine I just found this on d internet coz im looking for a copy byte codes.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I need help for this copy byte code ...

    Use a println statement to print out a question to the user.
    Use a method of the Scanner class to read the response from the user.

Similar Threads

  1. Copy Constructor
    By Rhyssa6 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 7th, 2021, 09:12 PM
  2. Byte Operation
    By tcstcs in forum Java Theory & Questions
    Replies: 4
    Last Post: March 27th, 2011, 11:19 PM
  3. I/O and byte arrays.
    By LDM91 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 1st, 2011, 08:36 PM
  4. UTF - 8 / Byte Stream
    By JavaCODER in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: October 16th, 2010, 02:26 PM
  5. byte[] from vector
    By perlWhite in forum Collections and Generics
    Replies: 1
    Last Post: August 26th, 2009, 05:10 AM