wiki:Tiedosto
Last modified 9 years ago Last modified on 2008-11-07 09:54:47

Tiedosto

Tiedosto is a class for dealing with files. It consists of methods for reading and writing a file. Look for the example usage below.

How to read a file

The method lueTiedosto will read a text file and return a string array with all the elements representing each line in the file. The first element in the returned array will have the content of the first line in the text file and so on. Here is an example (from Hangman2.java in D8T6):

String[] words = Tiedosto.lueTiedosto("words.txt");

If the content of the words.txt were:

house
winter
flute

the string array words would have three elements { "house", "winter", "flute" } inside.

And the same for the lists:

List<String> words = Tiedosto.lueTiedostoListaan("words.txt");