Skip to content

Instantly share code, notes, and snippets.

@risavkarna
Created September 30, 2012 12:54
Show Gist options
  • Save risavkarna/3806668 to your computer and use it in GitHub Desktop.
Save risavkarna/3806668 to your computer and use it in GitHub Desktop.
package hw1.rwFileSystemFile;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
public class ReadFile {
final static Charset ENCODING = StandardCharsets.UTF_8;
public static String[] readTextFile(String aFileName) throws IOException {
Path path = Paths.get(aFileName);
ArrayList<String> classIDs = new ArrayList<String>();
try (BufferedReader reader = Files.newBufferedReader(path, ENCODING)){
String line = null;
while ((line = reader.readLine()) != null) {
classIDs.add(line);
}
}
String[] strIDArray = classIDs.toArray(new String[classIDs.size()]);
return strIDArray;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment