je suis debutante en java, je dois ecrire un programme qui convertit une image bmp en tableau de byte, voici mon 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
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
 
 
 
public class image1 {
 
 
public static byte [] ImageToByte(File file) throws FileNotFoundException{
      //code of ImageToByte
	 FileInputStream fis = new FileInputStream(file);
     ByteArrayOutputStream bos = new ByteArrayOutputStream();
     byte[] buf = new byte[(int) file.length()];
     try {
         for (int readNum; (readNum = fis.read(buf)) != -1;) {
 
             bos.write(buf, 0, readNum);      
             System.out.println("read " + readNum + " bytes,");
         }
     } catch (IOException ex) {
     }
     byte[] bytes = bos.toByteArray();
     return bytes; 
    }}
--> et voici mon programme de test :


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
public class test {
 
	/**
         * @param args
         */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
 
	    try {
	       byte [] bytes = image1.ImageToByte(new File("C:/Users/loli/Desktop/Orange"));
 
	  }
	     catch (Exception e) {
	   e.printStackTrace();                                         
		     }       
		    }
	}



--> quand je compile, on me revoi :
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at image1.ImageToByte(image1.java:15)
at test.main(test.java:13)



j'arrive pas a trouver le probleme, est ce que vs pouvez m'aider svp ??