Created
September 30, 2012 12:54
-
-
Save risavkarna/3806668 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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