Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,39 @@
|
|||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
|
||||
/**
|
||||
* Reads a file line by line, processing each line.
|
||||
*
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class ReadFileByLines {
|
||||
private static void processLine(int lineNo, String line) {
|
||||
// ...
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (String filename : args) {
|
||||
BufferedReader br = null;
|
||||
FileReader fr = null;
|
||||
try {
|
||||
fr = new FileReader(filename);
|
||||
br = new BufferedReader(fr);
|
||||
String line;
|
||||
int lineNo = 0;
|
||||
while ((line = br.readLine()) != null) {
|
||||
processLine(++lineNo, line);
|
||||
}
|
||||
}
|
||||
catch (Exception x) {
|
||||
x.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
if (fr != null) {
|
||||
try {br.close();} catch (Exception ignoreMe) {}
|
||||
try {fr.close();} catch (Exception ignoreMe) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
for (String filename : args) {
|
||||
try (FileReader fr = new FileReader(filename);BufferedReader br = new BufferedReader(fr)){
|
||||
String line;
|
||||
int lineNo = 0;
|
||||
while ((line = br.readLine()) != null) {
|
||||
processLine(++lineNo, line);
|
||||
}
|
||||
}
|
||||
catch (Exception x) {
|
||||
x.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.charset.Charset;
|
||||
import java.io.IOException;
|
||||
//...other class code
|
||||
List<String> lines = null;
|
||||
try{
|
||||
lines = Files.readAllLines(Paths.get(filename), Charset.defaultCharset());
|
||||
}catch(IOException | SecurityException e){
|
||||
//problem with the file
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue