, , 2 1. , true, false.
, , , , , 1. 2 , .
. sts, , "" . , ArrayList. , .
Scanner reader = new Scanner(new File(f1));
ArrayList<String> out = new ArrayList<String>();
while (reader.hasNext()) {
String temp = reader.nextLine();
String[] sts = temp.split(" ");
for (int i = 0; i < sts.length; i++) {
if (sts[i].equals("") && sts[i].equals(" ") && sts[i].equals("\n")) {
out.add(sts[i]);
}
}
}
, , arraylist
while (reader.hasNext()) {
out.add(reader.next());
}
, , .
, 2 ,
dictionary.contains(file2.get(i))
equals ArrayList, , .
, , 2 . , 2 Scanner.
. , hasNextLine() hasNext() , hasNextLine() , .
line = reader.nextLine();
, true false + ,
String[] splitLine = line.split(" ");
for(String token: splitLine){
writer.write(dictionary.contains(file2.get(i))+" ");
}
, .
:
public class Test{
private static List<String> loadDictionary(String fileName) throws FileNotFoundException {
Scanner reader = new Scanner(new File(fileName));
List<String> out = new ArrayList<String>();
while (reader.hasNext()) {
out.add(reader.next());
}
reader.close();
return out;
}
public static void main(String[] args) throws IOException {
List<String> dictionary;
dictionary = loadDictionary("IbanDict.txt");
Scanner reader = new Scanner(new File("AFF_outVal.txt"));
OutputStreamWriter writer = new FileWriter(new File("out_test2.txt"));
while(reader.hasNextLine()){
String line = reader.nextLine();
String[] tokens = line.split(" ");
for(String token: tokens){
writer.write(dictionary.contains(token)+" ");
}
writer.write(System.getProperty("line.separator"));
}
writer.close();
reader.close();
}
}