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

'

...

.....

  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)); } '   

You can pass an 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

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -