Как сделать сценарий копирования-вставки с jcreator? - PullRequest
0 голосов
/ 10 сентября 2009

Вы можете помочь мне с кодировкой Java, поэтому я могу скопировать один файл с помощью командной строки.

Итак, я хочу запустить java-файл из командной строки Windows, например «java», мой java-скрипт »,« my file target »» и сделать копию моей «my file target» в том же каталоге без замены старого один.

пожалуйста, помогите мне?

Я вышел с этим

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 ]

2 голосов
/ 31 июля 2012
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
0 голосов
/ 10 сентября 2009

псевдо-код:

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)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...