bonjour,
c'est ma classe java :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
 
 
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
 
public class FilesFinder {
	String source = null;
    String destination = null;
    String sujet = null;
    String texte = "";
    String date_envoie_message = null;
    String bodyhtml = "";
    public static Connection conn;
    public static Statement stat;
 
    public FilesFinder() throws ClassNotFoundException, SQLException {
        Class.forName("org.sqlite.JDBC");
        conn = DriverManager.getConnection("jdbc:sqlite:synchro_outlook_android.s3db");
        stat = conn.createStatement();
        stat.executeUpdate("drop table if exists fichier;");
        stat.executeUpdate("create table fichier (date_envoie,source,destination,sujet,texte,bodyhtml,nom_dossier);");
        stat.executeUpdate("drop table if exists attachement;");
        stat.executeUpdate("create table attachement (nomattac,date_envoie);"); 
        stat.executeUpdate("drop table if exists image;");
        stat.executeUpdate("create table image (nomimage,date_envoie);");
    }
    public void insertFin(String path) throws IOException
    {
    	FileWriter writer = null;
		String texte = "FIN DU FICHIER";
		try{
		     writer = new FileWriter(path, true);
		     writer.write(texte,0,texte.length());
		}catch(IOException ex){
		    ex.printStackTrace();
		}finally{
		  if(writer != null){
		     writer.close();
		  }
 
		}
 
    }
    // procédure qui ouvre un dossier
    public  void findFiles(String directoryPath) throws SQLException, IOException {
        int nbligne = 1;
        String ligne = "";
        File directory = new File(directoryPath);
        File[] subfiles = directory.listFiles();
        for(int i=0 ; i<subfiles.length; i++)
        {
          System.out.println(subfiles[i].getName());
          System.out.println("-------------------------------------------");
          String nom_fich = subfiles[i].getName();
          String path = directoryPath+'/'+nom_fich;
          insertFin(path);
          HaveBody hb = new HaveBody(path);
          HaveText hv =  new HaveText(path);
          HaveImage hi = new HaveImage(path);
          HaveAttachement ha = new HaveAttachement(path);
          try{
             	FileInputStream fis = new FileInputStream(path);
                BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
                while (nbligne <8)
                  {
 
                   	ligne = reader.readLine();
                   	if(nbligne == 1)
                   	source = ligne;	
                    else if(nbligne == 3)
                    destination = ligne;
                   	else if(nbligne == 5)
                   	sujet = ligne;
                   	else if(nbligne == 7)
                   	date_envoie_message = ligne;
                   	nbligne++;
                    }
                     reader.close(); 
 
                     texte = hv.extractText();
 
                     bodyhtml = hb.extractBody();
 
                     hi.extractImage();
 
                     ha.extractAttachement();
 
 
                }
                catch (Exception e){
                	System.out.println(e.toString());
                }       
 
                PreparedStatement prep = conn.prepareStatement("insert into fichier values (?,?,?,?,?,?,?);");
                prep.setString(1,date_envoie_message );
                prep.setString(2, source);
                prep.setString(3, destination);
                prep.setString(4, sujet);
                prep.setString(5, texte);
                prep.setString(6, bodyhtml); 
                prep.setString(7, directoryPath);
                prep.addBatch();
                conn.setAutoCommit(false);
                prep.executeBatch();
                conn.setAutoCommit(true);
                for(int j = 0; j < hi.nbimage; j++)
                {
                	/*PreparedStatement prep1 = conn.prepareStatement("insert into image values (?,?);");
                    prep1.setString(1,date_envoie_message );
                    prep1.setString(2, hi.nomimage[j]);
                    */System.out.println(hi.nomimage[j]);
                    /*prep1.addBatch();
                    conn.setAutoCommit(false);
                    prep1.executeBatch();
                    conn.setAutoCommit(true);*/
                }
 
                for(int k = 0; k < ha.nbattach; k++)
                {
                //	PreparedStatement prep2 = conn.prepareStatement("insert into attachement values (?,?);");
                 //   prep2.setString(1,date_envoie_message );
                  //  prep2.setString(2, ha.nomattach[k]);
                	System.out.println(ha.nomattach[k]);
                   // prep2.addBatch();
                   // conn.setAutoCommit(false);
                   // prep2.executeBatch();
                   // conn.setAutoCommit(true);                
                }
 
 
                ResultSet rs = stat.executeQuery("select * from fichier;");
			    while (rs.next()) {
			      System.out.println("date_envoie = " + rs.getString("date_envoie"));
			      System.out.println("source = " + rs.getString("source"));
			      System.out.println("dest = " + rs.getString("destination"));
			      System.out.println("sujet = " + rs.getString("sujet"));
			      System.out.println("message = " + rs.getString("texte"));
			      System.out.println("bodyhtml = " + rs.getString("bodyhtml"));
 
			    }
			    rs.close();
			    conn.close();
 
        }
 
 
 
    }//fin 
 
    public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException {
        //initialisation
        FilesFinder finder = new FilesFinder();
        //ouvrir boite d'envoie
        finder.findFiles("C:/Boîte d'envoi");       
    }
}
elle donne le résultat souhaité pour un et un seul fichier mais elle ne fait pas le méme traitement pour les autres fichiers texte pour le répertoire donné "C:/boite d'envoie"..
voici l'erreur pour un et un seul fichier:

From Akram Dhiabi To ddd@ho.com.txt
-------------------------------------------
java.lang.NullPointerException
java.lang.NullPointerException
name="FIN.JPG"
filename="FIN.JPG"
date_envoie = Date: Sat, 6 Mar 2010 13:48:23 +0100
source = From: "Akram Dhiabi" <dhiabi.akram@gmail.com>
dest = To: <ddd@ho.com>
sujet = Subject: deza
message =
DEZFZEFZ
bodyhtml = <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD>

<META http-equiv=3DContent-Type content=3D"text/html; =

charset=3Diso-8859-1">

<META content=3D"MSHTML 6.00.6000.21183" name=3DGENERATOR>

<STYLE></STYLE>

</HEAD>

<BODY bgColor=3D#ffffff>

<DIV><FONT face=3DArial size=3D2>DEZFZEFZ</FONT></DIV></BODY></HTML>



mais pour d'autres fichiers textes :

From Akram Dhiabi To akr@ff.com.txt
-------------------------------------------
java.lang.NullPointerException
java.lang.NullPointerException
name="akr.jpg"
name="img.png"
date_envoie = Date: Sat, 6 Mar 2010 20:24:31 +0100
source = From: "Akram Dhiabi" <dhiabi.akram@gmail.com>
dest = To: <akr@ff.com>
sujet = Subject:
message =
ezfezfe




bodyhtml = <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD>

<META http-equiv=3DContent-Type content=3D"text/html; =

charset=3Diso-8859-1">

<META content=3D"MSHTML 6.00.6000.21183" name=3DGENERATOR>

<STYLE></STYLE>

</HEAD>

<BODY bgColor=3D#ffffff>

<DIV><FONT face=3DArial size=3D2>ezfezfe</FONT></DIV>

<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>

<DIV><IMG height=3D60 alt=3D"" hspace=3D0=20

src=3D"cid:9CDF65754E944C75BDCBEAF516E88F35@WOLF" width=3D96 =

align=3Dbaseline=20

border=3D0></DIV>

<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>

<DIV><IMG style=3D"WIDTH: 1440px; HEIGHT: 250px" height=3D592 alt=3D"" =

hspace=3D0=20

src=3D"cid:9BC52D5AC1AC468DB1F5EF04EAFA067A@WOLF" width=3D1440 =

align=3Dbaseline=20

border=3D0></DIV></BODY></HTML>
From Akram Dhiabi To akram@gmail.com.txt
-------------------------------------------
java.lang.NullPointerException
java.lang.NullPointerException
Exception in thread "main" java.lang.NullPointerException
at org.sqlite.PrepStmt.<init>(PrepStmt.java:37)
at org.sqlite.Conn.prepareStatement(Conn.java:231)
at org.sqlite.Conn.prepareStatement(Conn.java:224)
at org.sqlite.Conn.prepareStatement(Conn.java:213)
at FilesFinder.findFiles(FilesFinder.java:102)
at FilesFinder.main(FilesFinder.java:162)



de l'aide SVP !!