tags:

views:

76

answers:

1

Hi guys, can u help me with the coding of java, so i can copy a single file using command prompt.

so, i wanna run the java file from command prompt of windows, like "java "my java script" "my file target"" and make a copy of my "my file target" at the same directory without replace the old one.

please help me?

i came out with this

import java.io.*;
class ReadWrite {
    public static void main(String args[]) throws IOException {
     FileInputStream fis = new FileInputStream(args[0]);
     FileOutputStream fos = new FileOutputStream("output.txt");
     int n;
     if(args.length != 1)
      throw (new RuntimeException("Usage : java ReadWrite <filetoread> <filetowrite>"));
     while((n=fis.read()) >= 0)
      fos.write(n);
    }
}

but the copy of the file is named as output.txt can u guys help me with the coding, if i wanna choose my own output name? if i type "java ReadWrite input.txt (this is the output name that i want)" on command prompt

really need help here...

A: 

pseudo-code:

input = open input stream for file1
output = open output stream for file 2
while (input.read() has more bytes):
    write byte to output stream
close(input, output)
matt b
thanks, i will try it first
Stefannus Temaatmadja
good sir, can u help me again?
Stefannus Temaatmadja
Well if you are using args[0] to gain access to the first command line argument (the name of the input file), then it stands to reason that you could use args[1] to get access to a second command line argument and use that as the name of the output file.
matt b