It was troublesome to enter it for the test, so I was wondering if it could be done. As a result of investigation, by specifying ** FileInputStream ** that implements InputStream as the standard input It seems that it can be realized, so I wrote the code.
try {
InputStream stream = new FileInputStream("filename");
System.setIn(new FileInputStream(stream);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
/*
*Description of other data processing, etc.
*/
} catch (IOException e) {
e.printStackTrace();
}
I felt that it wasn't so when asked if there was another opportunity to use it. Generally, the file is read and processed normally.
Recommended Posts