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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| package GestionConfiguration;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;
import sun.util.calendar.LocalGregorianCalendar.Date;
public class FichierBis {
public FichierBis() {
}
public void findFiles(String directoryPath) {
File directory = new File(directoryPath);
//File name = null;
// verification des parametres
if(!directory.exists()){
System.out.println("Le fichier/répertoire '"+directoryPath+"' n'existe pas");
return;
}
if(!directory.isDirectory()){
System.out.println("Le chemin '"+directoryPath+"' correspond à un fichier et non à un répertoire");
return;
}
// liste des fichiers
File[] files = directory.listFiles();
String debut="20091029_202430",fin="_20091029_211300";
String date=debut.concat(fin);
for (int i=0;i<files.length;i++){
//System.out.println(files[0]);
//if ((files[i].getName().indexOf(debut) != -1)
// && (files[i].getName().indexOf(fin) != -1)) {
if ((files[i].getName().indexOf(date) != -1)){
System.out.println (files[i].getName());
}
}
}
public java.util.Date stringToDate(String str)
throws java.text.ParseException {// extrait la date du string
DateFormat df = new SimpleDateFormat("yyyyMMdd_hhmmss");
df.setLenient(false);// respect strict du format
java.util.Date date = null;
try {
date = df.parse(str);
} catch (ParseException e) {
e.getMessage();
}
return date;
}
public static String dateToString(Date sDate) // convertit date en string
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_hhmmss");
String s = sdf.format(sDate);
return s;
}
public Object count(File[] str) {
if (str != null) {
return str.length;
}
return null;
}
public void readbyte(File file){
FileInputStream fis;
int byteLu;
try{
//creation d'un flux d'entrée ayant pour source un fichier nommé
//source,cette instanciation peut lever une exception de type
//FileNotFound
fis=new FileInputStream("file");
//la methode read() renvoie un int representant l'octet lu, la valeur (-1)
//represente la fin du fichier.
// read peut lever une exception du type IOException
try{
while((byteLu=fis.read())!=-1){
System.out.println(byteLu);
}
}
//Ne pas oublier de fermer le flux afin de liberer les ressources qu'il
//utilise
finally{
fis.close();
}
}
catch(FileNotFoundException ef){
System.out.println("fichier introuvable");
}
catch(IOException e){
System.out.println(e+"erreur lors de la lecture du fichier");
}
}
public static void main(String[] args) throws IOException {
// "C:/Documents and Settings/massamba/workspace/ORBIT_EPHEM"
FichierBis ef = new FichierBis();
ef.findFiles("C:/Documents and Settings/massamba/workspace/ORBIT_EPHEM");
File file= new File("C:/Documents and Settings/massamba/workspace/ORBIT_EPHEM/ORBIT_EPHEMERIS_20091029_202430_20091029_211300");
//System.out.println(file.read());
ef.readbyte(file);
}
} |