简体   繁体   中英

how to make a copy-paste script with jcreator?

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...

import java.util.Scanner;

public class program_23{ // start of class

    public static void main(String []args){  // start of main function.

        Scanner input = new Scanner (System.in);

        // decleration  ang initialization of variables
        String name = " ";
        int age  = 0;
        int no_of_hour_work = 0;
        double daily_rate = 0.0;

        // get user input
        System.out.print("Employee Name: ");
        name = input.nextLine();

        System.out.print("Employee Age: ");
        age = input.nextInt();

        System.out.print("No of hour(s) work: ");
        no_of_hour_work = input.nextInt();

        // compute for daily rate
        daily_rate = no_of_hour_work * 95.75;

        // display the daily rate
        System.out.print("Dialy rate:"+ daily_rate);

    }// end of main

}// end of class

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM