In Java, you can use the write
method of the PrintStream
class to write a single character or an array of bytes to the standard output stream.
Here's an example of how to use the write
method to write a single character to the standard output stream:
System.out.write('A');
In this example, the write
method writes the character 'A'
to the standard output stream.
You can also use the write
method to write an array of bytes to the standard output stream:
byte[] bytes = { 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd' }; System.out.write(bytes, 0, bytes.length);
In this example, the write
method writes the array of bytes bytes
to the standard output stream, starting from the first element (index 0) and writing all the elements of the array (bytes.length
elements).
Note that the write
method does not automatically add a newline character at the end of the output, unlike the println
method. If you want to print a newline character after the output, you can use the println
method or use the write
method to write a newline character:
System.out.write('\n');
You can find more information about the write
method and how to use it in Java in the Java documentation.