从命令行输入
参考:https://fishc.com.cn/thread-205615-1-1.htmlimport java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
public class main {
public static void output(String filename) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
String s; while((s = br.readLine()) != null) System.out.println(s);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
output(scanner.next());
}
}
复制文件import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class main {
public static void copy(String src, String dest) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(src)));
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(dest));
String s; while((s = br.readLine()) != null) writer.append(s + "\n");
writer.close();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
copy("main.java", "temp.txt");
}
}
把这两个代码合并一下不就可以了?这真的是很基础的知识
我怀疑你看不懂我写的代码,你就只是想要一个能够通过测试的代码
|