| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 
 |  
 public byte[] FileToByte(java.io.File fichier) throws IOException {
    	InputStream is = new FileInputStream(fichier);
    	long length = fichier.length();
 
    	if (length>Integer.MAX_VALUE){
    		System.out.println("fichier trop gros");
    	}
 
    	byte[] tableau = new byte[(int) fichier.length()];
 
    	int offSet = 0;
    	int numRead = 0;
    	while (offSet < tableau.length && (numRead=is.read(tableau, offSet,tableau.length-offSet)) >= 0) {
    		offSet += numRead;
    	}
 
    	if (offSet < tableau.length) {
    		throw new IOException("Ne peut pas lire le fichier " +fichier.getName()+ " complétement.");
    	}else {
    		System.out.println("Fichier lu correctement...");}
 
    	is.close();
 
    	return tableau;
    } | 
Partager