如何使用jcreator制作复制粘贴脚本?

时间:2009-09-10 03:29:26

标签: java

你可以帮我编写java代码,所以我可以使用命令提示符复制单个文件。

所以,我想从windows的命令提示符运行java文件,比如“java”我的java脚本“”我的文件目标“”并在同一目录下制作我的“我的文件目标”的副本而不替换旧的之一。

请帮帮我?

我出来了

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);
    }
}

但该文件的副本名为output.txt 如果我想选择自己的输出名称,你们可以帮我编码吗? 如果我在命令提示符下键入“java ReadWrite input.txt(这是我想要的输出名称)”

在这里真的需要帮助......

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

伪码:

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)