As an amateur java learner i was trying out different combinations of java file and I/O methods, as i tried out this code where i wanted to print whatever i entered into the file
public class Dhoom3
public static void main(String args) throws IOException, NullPointerException
FileWriter b = new FileWriter(new File("tom.txt"));
System.out.println(" enter whatever : ");
System.out.println("the printed characters are");
FileInputStream r = new FileInputStream("tom.txt");
BufferedInputStream k = new BufferedInputStream(r);
while((g = k.read())!= -1)
enter whatever :
the printed characters are
Your error is using
to read input.
System.in.read only reads one byte of input.
The better alternative to this is to use Scanners. Scanners can scan multiple bytes of information, so they are better for what you are doing.
To fix your code:
1) Create a new Scanner object like so:
Scanner scanner = new Scanner(System.in);
2) Replace System.in.read with: