...
Code Block | ||
---|---|---|
| ||
class FileWrite { public static void main(String[] args) throws NumberFormatException, IOException { FileOutputStream out = new FileOutputStream("output"); //Perform range checking if(Integer.valueOf(args[0]) < 0 || Integer.valueOf(args[0]) > 255) { throw new ArithmeticException("Value is out of range"); } out.write(Integer.valueOf(args[0].toString())); System.out.flush(); } } |
Note that a NumberFormatException
results when attempting to use the Integer.valueOf()
method, if args0
contains a value that is larger than the maximum value of an int
.
Compliant Solution (3)
This compliant solution uses the writeInt()
method of the DataOutputStream
class.
...