IO重定向
作者:
RwChen
,
2023-04-07 10:39:22
,
所有人可见
,
阅读 211
// c++
#include <bits/stdc++.h>
using namespace std;
int main() {
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
return 0;
}
手动分界
// java
import java.io.*;
import java.util.Scanner;
public class Main {
private static void redirectInput() throws FileNotFoundException { // 重定向stdin到文件
InputStream fin = new FileInputStream("in.txt");
System.setIn(fin);
}
private static void redirectOutput() throws FileNotFoundException { // 重定向stdout到文件
OutputStream fout = new FileOutputStream("out.txt");
PrintStream fps = new PrintStream(fout);
System.setOut(fps);
}
public static void main(String[] args) throws FileNotFoundException { // test code
redirectInput();
redirectOutput();
Scanner sc = new Scanner(System.in);
// System.out.println("redirect...");
// for (int i = 0; i < 200; ++i) System.out.println(i);
while (sc.hasNextLine()) {
System.out.println(sc.nextLine());
}
}
}