Mise à jour nom du fichier
J'ai écrit le code suivant pour lire un fichier texte et pour extraire les fichier.Mais le problème que le nom du fichier change chaque jour (par exemple:nom du fichier="10032016.BDE".J'ai pas su comment changer la destination automatiquement
Code:
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| package houssem;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
public class ReadWithScanner {
public static void main(String... aArgs) throws IOException, InterruptedException {
int j =0;
Boolean c=true;
do{ int a=count();
String b=null;
int ki=0;
ReadWithScanner parser = new ReadWithScanner("C:\\ERROR\\05122015.BDE");
try (Scanner scanner = new Scanner(parser.fFilePath)){
if(c){
while (scanner.hasNextLine()) {ki++;b=scanner.nextLine();
if(ki>20)
{processLine(b);
}
j++;c=false;
}}
}
if(j<a) {Scanner scanner1 = new Scanner(new File("C:\\ERROR\\05122015.BDE"));
String line = null;
while (scanner1.hasNextLine()) {
line = scanner1.nextLine();}
int k=countwords(line);
if(k>=9){ processLine(line);j++;}
scanner1.close();}
Thread.sleep(1000);
}while(true);
}
public static int count() throws IOException{
int j = 0;
ReadWithScanner parser = new ReadWithScanner("C:\\ERROR\\05122015.BDE");
try (Scanner scanner = new Scanner(parser.fFilePath)){
while (scanner.hasNextLine()) { j++;
scanner.nextLine(); }
}
return(j);
}
public static int countwords(String line) throws IOException{
int j=0;
Scanner s=new Scanner(line);
while(s.hasNext()){ j++;s.next();}
return(j); }
public ReadWithScanner(String aFileName){
fFilePath = Paths.get(aFileName);
}
protected static void processLine(String aLine){
Scanner scanner = new Scanner(aLine);
scanner.useDelimiter(" ");
if (scanner.hasNext()){
String value = scanner.next();
String name = scanner.next();
String value2 = scanner.next();
String value3 = scanner.next();
String value4 = scanner.next();
System.out.println( quote(value.trim())+" "+ quote(name.trim())+" "+quote(value2.trim())+quote(value3.trim())+quote(value4.trim()));
}
else {
System.out.println("invalid line");
}
scanner.close();
}
private Path fFilePath;
private static String quote(String aText){
return aText;}
} |
Merci pour votre aide