j'ai un fonction qui remplie un repertoire avec des fichier et une autre fonction qui lit ces fichier et le traite mais il m'affiche que les fichier n'existe pas
voilà mon code:
import java.io.*;
public class tous
{
public static String requete = "java";
public File rep = new File("temp1");
public static void main (String argv [ ]) throws IOException
{
fonct1 ();
fonct2();
}
public static void fonct1 (){
class connexion extends Thread {
String nom;
String nomf;
connexion (String s,String d ) {
nom=s;
nomf=d;
}
public void run()
{ try
{ String query = URLEncoder.encode(requete);
URL url = new URL(nom+query);
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
String userAgent = "agent utilisateur" ;
uc.setRequestProperty("User-Agent", userAgent);
InputStream in = uc.getInputStream();
int c =0;
StringBuffer build = new StringBuffer();
while (c != -1)
{
c = in.read()<<8;
c=c | (in.read());
build.append((char) c);
}
File f = new File("temp1/"+nomf+".txt");
DataOutputStream flux = new DataOutputStream(new FileOutputStream(f));
flux.writeChars(build.toString());
flux.close();
}
catch (MalformedURLException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
}
}
if(!rep.exists()){
rep.mkdirs();
}
for(int i=0;i<m;i++)
{
Thread T1 = new connexion( listselect1[i][1], listselect1[i][0]);
T1.start();
}
}
public static void fonct2()
{
String g= fichtostr("temp1/"+listselect1[h][0]+".txt");
// traitement sur g
}
public static String fichtostr(String nomf)
{
String tout = "" ;
try {
String ligne = "" ;
BufferedReader reader = new BufferedReader( new FileReader(nomf) );
while( (ligne = reader.readLine()) != null)
{
tout += ligne;
}
}
catch (IOException e) {
System.err.println(" Cela ne marche pas. Voila." + e.toString());
}
return tout;
}
public static String remplacer(Matcher recherche, String remplacement)
{
return(recherche.replaceAll(remplacement));
}
//Clean up resources
public void destroy() {
}
amel2006 