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");
}
}
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");
}
}