How to rectify void not allowed here and can not be applied here error?


There is method which is generating content.html.

contentPage(new PrintStream(socket.getOutputStream(), false));

I want to see the content, I tried

br.write("Content Page: : : "+contentPage());

but got the error

contentPage( can not be applied..

I tried

br.write("Content Page: : : "+contentPage(ps));

where ps is reference for PrintStream, and got the error

void type not allowed here

I am new to Java, Kindly help me out to print the content.

You could call contentPage(ps) twice:

contentPage(new PrintStream(socket.getOutputStream(), false));

to output the html to the console,

Or, you can put the html in a buffer first:

ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(bos, false);
byte[] data = bos.toByteArray();

OutputStream out = socket.getOutputStream();

br.write("Content Page: : : " + new String(data));