I have no idea what you mean by โimportingโ a file, but here is the easiest way to open and read a text file line by line using only standard Java classes. (This should work for all versions of Java SE in JDK1.1. Using Scanner is another option for JDK1.5 and later.)
BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(fileName)));
try {
String line;
while ((line = br.readLine()) != null) {
}
} finally {
br.close();
}
source
share