Stuck with FileOutputStream

C

charly

Greetings,

I'm trying to copy a file (an image) and fails :

the file is read, the array created, the output stream created, flushed,
closed but no file is created at the end of the process (no Exception,
no Warning )

It shouldn't :)

I work on Linux (but I would get a warning if there were a permission
problem) JDK is 1.4.2


Must be easy but I cannot spot the problem :(

thx a lot if someone can shed some light on this !

import java.awt.Toolkit;
import java.io.*;
import javax.swing.JFrame;


public class Lecteur extends JFrame {

/** Creates a new instance of Lecteur */
public Lecteur() {

//FileChooser.showOpenDialog(this);
}

public void readFile(String nomFich) {

//JFileChooser FileChooser = new JFileChooser();
byte[] TabBytes = new byte[3000];
try{

InputStream input =
this.getClass().getResourceAsStream(nomFich);

input.read(TabBytes);
input.close();



File f = new File("img.png");
//Création d'une copie du doc à partir du tableau
FileOutputStream out = new FileOutputStream(f);
out.write(TabBytes);
out.close();
System.out.println(TabBytes.length);


}
catch (Exception ex){
ex.printStackTrace();
}


}

public void readText(String nomFichier){
byte[] TabBytes = new byte[3000];

/*try{

InputStream input =
this.getClass().getResourceAsStream(nomFich);

input.read(TabBytes);
input.close();
*/

}

public void Affiche(String msg){

System.out.println(msg);
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {



Lecteur test = new Lecteur();
test.readFile("server-cfg.png");
//test.readText("Lecteur.java");




}



}
 
C

charly

The program actually worked, It just did not create the file where I
thought it would :(

Sorry for bothering you people :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top