mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
davhojt
1cf114eb85
|
1 year ago | |
---|---|---|
.. | ||
README.md | 1 year ago |
README.md
CatInFile
Instructions
Create a file named CatInFile.java
.
Write a function cat
that reads from standard input and write to file given as parameter.
⚠️ You may read from the input some binary content.
💡 Be aware of how much you read at once.
Expected Functions
import java.io.*;
public class CatInFile {
public static void cat(String[] args) throws IOException {
// your code here
}
}
Usage
Here is a possible ExerciseRunner.java to test your function :
import java.io.*;
public class ExerciseRunner {
public static void main(String[] args) throws IOException {
String input = "input file test\n";
ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
CatInFile.cat(new String[]{"output"});
String fileContent = new String(Files.readAllBytes(Paths.get("output")));
System.out.println(fileContent.equals(input));
}
}
and its output :
$ javac *.java -d build
$ java -cp build ExerciseRunner
true
$