Posts Tagged ‘file’

How to copy a file using Java 6

Java, Tip 10.7.2015 No Comments

Prior to Java 7, Java did not provide a standard method to copy a file. To implement copying you needed to read all bytes from source file and write to destination. The read() method will return -1 when eof is reached, otherwise it returns the number of bytes read.

Read More

Using Scanner to read words from text file

Java, Tip 20.11.2014 1 Comment

Often you need to read a file line by line. Alternatively sometimes you want to read text word by word (for example to count the occurrence of different words). The Scanner classes next() method can be used for this as shown in the following example. You can find an example of the use of the…

Read More

How do I read a text file line by line?

Java, Tip 20.11.2013 No Comments

The readLine() method of class reads the next line from a text file. When it reaches the end of the file it will return null.

Read More