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.
 
 
 
 
 
 
zanninso 34d030760e docs: fix formatting 4 months ago
..
README.md docs: fix formatting 4 months ago

README.md

Cat

Instructions

Create a file named Cat.java.

Write a function cat that reads the content of the file given as the argument, and writes it's content 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 {
        PrintStream stdout = System.out;

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        PrintStream printStream = new PrintStream(outputStream);
        System.setOut(printStream);

        Cat.cat(new String[]{"input.txt"});
        String output = outputStream.toString();
        // Reset out to stdout
        System.setOut(stdout);
        System.out.println(output.equals("test input file\n"));

        ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream();
        PrintStream printStream2 = new PrintStream(outputStream2);
        System.setOut(printStream2);

        Cat.cat(new String[]{});
        String output2 = outputStream2.toString();
        // Reset out to stdout
        System.setOut(stdout);
        System.out.println(output2.equals(""));
    }
}

and its output :

$ javac *.java -d build
$ java -cp build ExerciseRunner
true
true
$

Notions

Command-Line Arguments File Standard Output IOException