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.
1.7 KiB
1.7 KiB
Cat
Instructions
Create a file named Cat.java
.
Write a function cat
that reads from a file given as a parameter and writes to the standard output.
⚠️ The files can have some binary content.
💡 Be aware of how much you read at once.
Expected Functions
import java.io.*;
public class Cat {
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 {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);
System.setOut(printStream);
Cat.cat(new String[]{"input"});
String output = outputStream.toString();
System.out.println(outputStream.toString().equals("test input file\n"));
ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream();
PrintStream printStream2 = new PrintStream(outputStream);
System.setOut(printStream2);
Cat.cat(new String[]{});
String output = outputStream2.toString();
System.out.println(outputStream2.toString().equals(""));
}
}
and its output :
$ javac *.java -d build
$ java -cp build ExerciseRunner
true
true
$