Bonjour tout le monde ;
j'ai une méthode qui me retourne le contenue d'un fichier sous format d'un string.voici le code :

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
public String scGetContentOfFlux(InputStream in) {
		LOG.debug("Appel de la méthode GererRecensementDiseImpl.scGetContentOfFlux : Lecture des valeurs \n");
		String txtGenerique = null;
		try {
			// Lecture par segment de 0.5Mo 
			byte buffer[]=new byte[512*1024];
			int nbLecture;
 
			// lecture du fichier d'origine et dump dans un String
			ByteArrayOutputStream bytes = new ByteArrayOutputStream();
			while( (nbLecture = in.read(buffer)) != -1 ) {                	
				bytes.write(buffer, 0, nbLecture);
			}
			txtGenerique = bytes.toString();			
			txtGenerique = txtGenerique.replaceAll("\r\n",";"); // remplacer les retour à la ligne par des ;
			txtGenerique = txtGenerique.substring(0, txtGenerique.length()-1); // supprimer le dernier ;
 
		}
		catch( java.io.IOException e ) {
 
		} finally {
			// Quoi qu'il arrive, on ferme les flux
			try {
				in.close();
			} catch(Exception e) { }
		}
		return txtGenerique;
	}
Cette fonction marche très bien si le fichier (qui est convertit en input stream contient des caractère ou donnée),mais si j'ai un fichier vide, apr exemple fichier texte vide, j'obtient l'exception suivante :

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
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(II)Ljava/lang/String;(Unknown Source)
	at com.francetelecom.webvpn.services.recensement.GererRecensementDiseImpl.scGetContentOfFlux(Ljava/io/InputStream;)Ljava/lang/String;(GererRecensementDiseImpl.java:1465)
	at jrockit.reflect.NativeMethodInvoker.invoke0(Ljava/lang/Object;ILjava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Unknown Source)
	at jrockit.reflect.NativeMethodInvoker.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Unknown Source)
	at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Unknown Source)
	at java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;I)Ljava/lang/Object;(Unknown Source)
	at com.francetelecom.webvpn.service.ServiceManager.invoke(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;(ServiceManager.java:142)
	at $Proxy3.scGetContentOfFlux(Ljava/io/InputStream;)Ljava/lang/String;(Unknown Source)
	at com.francetelecom.webvpn.struts.RecensementDISEAction.importerValeursExcel(Lorg/apache/struts/action/ActionMapping;Lorg/apache/struts/action/ActionForm;Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)Lorg/apache/struts/action/ActionForward;(RecensementDISEAction.java:957)
	at jrockit.reflect.NativeMethodInvoker.invoke0(Ljava/lang/Object;ILjava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Unknown Source)
	at jrockit.reflect.NativeMethodInvoker.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Unknown Source)
	at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Unknown Source)
	at java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;I)Ljava/lang/Object;(Unknown Source)
	at org.apache.struts.actions.DispatchAction.dispatchMethod(Lorg/apache/struts/action/ActionMapping;Lorg/apache/struts/action/ActionForm;Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Ljava/lang/String;)Lorg/apache/struts/action/ActionForward;(DispatchAction.java:276)
	at org.apache.struts.actions.DispatchAction.execute(Lorg/apache/struts/action/ActionMapping;Lorg/apache/struts/action/ActionForm;Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)Lorg/apache/struts/action/ActionForward;(DispatchAction.java:196)
	at com.francetelecom.webvpn.struts.WebVPNDispatchAction.execute(Lorg/apache/struts/action/ActionMapping;Lorg/apache/struts/action/ActionForm;Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)Lorg/apache/struts/action/ActionForward;(WebVPNDispatchAction.java:241)
	at org.apache.struts.action.RequestProcessor.processActionPerform(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Lorg/apache/struts/action/Action;Lorg/apache/struts/action/ActionForm;Lorg/apache/struts/action/ActionMapping;)Lorg/apache/struts/action/ActionForward;(RequestProcessor.java:421)
	at org.apache.struts.action.RequestProcessor.process(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V(RequestProcessor.java:226)
	at com.francetelecom.clara.security.struts.action.SecuredRequestProcessor.process(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V(SecuredRequestProcessor.java:165)
	at org.apache.struts.action.ActionServlet.process(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V(ActionServlet.java:1164)
	at org.apache.struts.action.ActionServlet.doPost(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V(ActionServlet.java:415)
	at javax.servlet.http.HttpServlet.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V(HttpServlet.java:763)
	at javax.servlet.http.HttpServlet.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V(HttpServlet.java:856)
	at jrockit.reflect.NativeMethodInvoker.invoke0(Ljava/lang/Object;ILjava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Unknown Source)
	at jrockit.reflect.NativeMethodInvoker.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Unknown Source)
	at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Unknown Source)
	at java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;I)Ljava/lang/Object;(Unknown Source)
	at org.apache.catalina.security.SecurityUtil$1.run()Ljava/lang/Object;(SecurityUtil.java:243)
	at jrockit.vm.AccessController.do_privileged_exc(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;I)Ljava/lang/Object;(Unknown Source)
	at jrockit.vm.AccessController.doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;(Unknown Source)
	at javax.security.auth.Subject.doAsPrivileged(Ljavax/security/auth/Subject;Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;(Subject.java:500)
	at org.apache.catalina.security.SecurityUtil.execute(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;Ljava/security/Principal;)V(SecurityUtil.java:272)
Caused by =

est-ce que c'est car le fichier est vide??Merci pour votre aide.