Chemin d'accès à un fichier en Java
Bonsoir,
Je veut pouvoir extraire chaque image d'un dossier afin de faire des traitements dessus mais ça ne veut pas marcher puisque mon fichier contient plusieurs images donc il faut que je fasse une boucle pour accédé a chaque image de mon fichier du coup le nom de mon chemin change a chaque fois et quand je concatène le nom d'une image a mon chemin ça ne marche pas :( je ne comprend pas
Voici mon code
Code:
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
|
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package image;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
*
* @author bureau
*/
public class Image {
/**
* @param args the command line arguments
*/
//Methode 1-> pour compter le nombre d'image dans le fichier
public int nbrImages(){
File repertoire=new File("C:\\\\Users\\\\bureau\\\\Desktop\\\\M2\\\\IMM\\\\Tp\\\\IMM");
String [] listeimages;
listeimages=repertoire.list();
return listeimages.length;//length->definit la longeur d'un tableau
}
public String [] ContenuFichier(){
File repertoire=new File("C:\\\\Users\\\\bureau\\\\Desktop\\\\M2\\\\IMM\\\\Tp\\\\IMM");
String [] listeimages;
listeimages=repertoire.list();
return listeimages ;
}
public static void main(String[] args) throws IOException {
int nbrImag;
String [] contenu;
Image I=new Image();
nbrImag=I.nbrImages();//le nombre d'image du fichier
contenu =I.ContenuFichier();//Le contenu du fichier
BufferedImage b;
for(int compte=0; compte<nbrImag ;compte++){
b = ImageIO.read(new File("C:\\Users\\bureau\\Desktop\\M2\\IMM\\Tp\\IMM\\"+contenu[compte]+".jpg"));
int h = b.getHeight();
int w = b.getWidth();
Color[][] image = new Color[w][h];
for(int wi=0; wi<w; wi++){
for(int hi=0; hi<h; hi++){
Color pixel = new Color(b.getRGB(wi, hi));
image[wi][hi] = pixel;
System.out.println("Case :"+"["+wi+"]"+"["+hi+"]"+pixel);
}
} }
}
} } |
et voici l'erreur
Code:
1 2 3 4
| Exception in thread "main" javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1301)
at image.Image.main(Image.java:53)
Java Result: 1 |
je vous remercie d'avance