banner



How To Draw Random Lines From File Java

Member Avatar

Apply a BufferedReader with the readLine() method. You tin either skip lines every bit you read them, or place each line into an ArrayList, and process them every bit needed.

Member Avatar

readLine() but sequentially reads lines from the file. If you only care well-nigh certain lines, maintain a counter as the lines are read and print/store/whatever lines you lot need based upon that counter.

              int lineNumber=0; Cord line=null; while ( (line = br.readLine()) != naught){   lineNumber++;   if ( <some expression on lineNumber> ){     // do something   } }            

Member Avatar

If yous desire to randomly nowadays lines from the file, I would read all of the lines into an ArrayList first so become() them with a random int of the range 0 to size()-1.

Member Avatar

Thanks a lot, I got it to work at present!

Member Avatar

Expect into the RandomAccessFile class. The only downside being the file is a treated as a sequence of bytes rather than the conventional line oriented view which many are used to. This course is especially for example useful when you want to come up with your custom file format which would accept a fixed header size.

Member Avatar

I am non quite sure that I sympathise what you lot are trying to say hither but if you are worried about the number of characters displayed per line on your console window, information technology depends on the properties of the console window (OS specific) and has got nothing to practice with your programme. For e.thou. in Windows you can set the properties of the console window similar Screen buffer and window size to increase / display the number of characters displayed.

If still in doubt, post the code forth with the varying output you are talking nigh.

Member Avatar

Yes, fifty-fifty whitespace counts as a character. To detect a whitespace, use the function Character.isWhitespace(char ch) .

Source: https://www.daniweb.com/programming/software-development/threads/110393/how-to-output-random-line-from-a-file

Posted by: lopezdresse.blogspot.com

0 Response to "How To Draw Random Lines From File Java"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel