1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
public static void main(String[] args) throws IOException
{
System.out.println("Date de début : " + new Date());
File fich = new File("C:\\FTP\\test_java.txt");
int n;
char c;
Collection<String> col = new HashSet<String>();
StringBuilder builder = new StringBuilder();
Reader fr = null;
try {
fr = new BufferedReader(new FileReader(fich), 8192 * 1024);
while ((n = fr.read()) != -1)
{
c =(char) n;
if (c != ' ' && c != '\r' && c != '\n' && c != '.' && c != ',' && c != ';' && c != ':'
&& c != '!' && c != '?' && c != '/' && c != '\\' && c != '$' && c != '"'
&& c != '&' && c != '(' && c != ')' && c != '[' && c != ']'
&& c != '{' && c != '}' && c != '@' && c != '*' && c != '%' && c != '-'
&& c != '*' && c != '+' && c != '=')
builder.append(c);
else
{
if (builder.length() > 3 && !col.contains(builder.toString().toLowerCase()))
col.add(builder.toString().toLowerCase());
builder.setLength(0);
}
}
System.out.println("Date de fin : " + new Date());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally {
System.out.println(col);
fr.close();
col.clear();
col = null;
}
} |
Partager