Create a java project with eclipse, as shown in the screen shot

Create a text file and save it in the project folder

Complete Code :

/**
*
*/
import java.io.FileInputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* @author Manas9
*
*/
public class ClassTemplate1 {

/**
*
*/
public ClassTemplate1() {
// TODO Auto-generated constructor stub
}

/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
InputStream inStream = new FileInputStream("test.txt");
OutputStream outStream = System.out;

ReadOutputStream readoutStream = new ReadOutputStream(outStream);
for (int n1 = inStream.read(); n1 != -1; n1 = inStream.read()) {
readoutStream.write(n1);
}
readoutStream.close();// stream closed

}

}
class ReadOutputStream extends FilterOutputStream {

public ReadOutputStream(OutputStream xout) {
super(xout);
}

public void write(int buff) throws IOException {

OutputStream yout = System.out;
// carriage return n, linefeed r, and tab t
if (buff == '\n' || buff == '\r' || buff == '\t')
{
yout.write(buff);
// non-printable chars
}
else if (buff < 32 || buff > 126){
// write, ASCII characters
yout.write('?');
}

else{
yout.write(buff);}
}

public void write(byte[] data, int offset, int strlength) throws IOException {
for (int i = offset; i < offset + strlength; i++) {
this.write(data[i]);
}
}
}
 

Run time view