1. Question: The task states the following:
try (
FileOutputStream outputStream = new FileOutputStream(args[0]);
InputStream is = Solution.class.getClassLoader().getResourceAsStream(args[1]);
) {
;
byte[] b = new byte[is.available()];
....
I have set the second parameter to a valid file, but when I run this in IntelliJ, a NullPointerException is thrown on line 6 because the variable "is" is null - and null, of course, does not have an available() method.
If I replace line 3 with the following, everything works fine:
InputStream is = new FileInputStream(args[1]);
But according to the task, the only error is the wrong if statement.
Does the command "Solution.class.getClassLoader().getResourceAsStream(args[1])" really work? And if so, how?
2. Question: According to the task, the following line should be correct:
outputStream.write(is.read(b));
"is.read(b)" returns the number of bytes read as an integer.
"outputStream.write()" writes this integer as a byte to the file - makes no sense to me, or am I missing something?
Anyway, as expected, there is only one ascii character in my output file.
Best regards.