java - Reading a file of txt to be fed into an array -
Here a user enters the list of 1 and 0 .... then an input will be 10001010. But I have to read this from a text file ... In my text file input.txt there are also 10001010 ... the coverDataArray array is required to feed the same string from a file to the console.
I tried the data stream though, it throws an exception to me
' ... ..... You can pass an
try {System.out.println ("Enter binary bits" ); Data1 = in.next (); For (int i = 0; i & lt; data1.length (); i ++) {covertDataArray [i] = byte Parsbyte (data 1.substring (i, i + 1)); } '
file object instead For the
System.in scanner constructor it is shown below:
string filename = "input.txt"; File file = new file (filename); Scanner scanner = new scanner (file); String s = ""; While (scanner.hasNextLine ()) {s = scanner.nextLine (); // your code. You can use scanner.next () to read words by word instead of nextLine ()} .
Comments
Post a Comment