import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class RedirectIn {
public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream("RedirectIn.java");
System.setIn(fis);
Scanner sc = new Scanner(System.in);
sc.useDelimiter("\n");
while (sc.hasNext()) {
System.out.println("键盘输入的内容是:" + sc.next());
}
if (fis != null ) {
fis.close();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
|
|