Java 7 has now made it easier to do what I wrote here, longer ago now than I care to remember. You can get a Collection of String from a file pretty easily. The source code can be downloaded HERE. Of course, if you're still using < Java 7, you can use the earlier code.
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.util.List;
public class StringListDemo {
public static void main(String[] args) {
try {
List<String> strings = Files.readAllLines(FileSystems.getDefault()
.getPath("strings.txt"),
Charset.forName("UTF-8"));
System.out.println(strings);
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.nio.charset.Charset;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.util.List;
public class StringListDemo {
public static void main(String[] args) {
try {
List<String> strings = Files.readAllLines(FileSystems.getDefault()
.getPath("strings.txt"),
Charset.forName("UTF-8"));
System.out.println(strings);
} catch (IOException e) {
e.printStackTrace();
}
}
}