Program to print message without println() method in java?

There are multiple way to print message without println() method in java.

Using Output Streams :-

  • Create a OutputStreamWriter object.
  • Use streamWriter.write method to print the data.

              Syntax :- public void write(String str) throws IOException

Using write method :-

  • This method write data in byte stream form and print data.

               Syntax :- public void write(int b);

Using Print Stream method :-

  • Create a printStream Object to write the data.
  • Read data from out.print method.

              Syntax :-  public PrintStream(OutputStream out)

Using error.print method :-

  • System.error print the data on console.
  • It is printing the exception.
				
					import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintStream;

public class WithoutSOP {

	public static void main(String[] args) throws IOException {
		
		// Using Output Streams
		OutputStreamWriter streamWriter = new OutputStreamWriter(System.out);
		streamWriter.write("welcome to javatechnote");
		streamWriter.flush();
		
        //Using write method
		System.out.write('\n');
		System.out.write("java world".getBytes());
		System.out.write('\n');
		
		// using Print Stream
		PrintStream out = new PrintStream(new FileOutputStream(FileDescriptor.out));
		out.print("write the file");
		System.out.write('\n');
		out.close();
		
       //Using error.print
		System.err.print("error data");
	}
}

				
			

Output :-
welcome to javatechnote
java world
write the file
error data