Probleme fichier en java

Résolu/Fermé
bouchrot Messages postés 352 Date d'inscription mercredi 12 octobre 2011 Statut Membre Dernière intervention 2 janvier 2023 - 7 janv. 2012 à 13:02
 oxander25 - 4 mai 2012 à 01:24
Bonjour,

salut que quelqu'un me corrige cet exercice s'il vous plait


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Filemain2 {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(new File("test.txt"));
fos = new FileOutputStream(new File("test2.txt"));
byte[] buf = new byte[8];
int n = 0;
while((n = fis.read(buf)) >= 0)
{
fos.write(buf);
for(byte bit : buf)
System.out.print("\t" + bit + "(" + (char)bit + ")");
System.out.println("");
}
System.out.println("Copie terminée !");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
try{
if(fis != null)
fis.close();
if(fos != null)
fos.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
}

il se compile mais il m'affiche un message disant que
java.io.FileNotFoundException: test.txt (Le fichier spécifié est introuvable)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at filemain2.Filemain2.main(Filemain2.java:17)

merci

A voir également:

1 réponse

KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
7 janv. 2012 à 13:03
Essayes de mettre le chemin complet de tes fichiers "C:\\...\\test.txt"
3
bouchrot Messages postés 352 Date d'inscription mercredi 12 octobre 2011 Statut Membre Dernière intervention 2 janvier 2023 6
7 janv. 2012 à 18:27
ça marcher , je te remercie
0
Exacten un grand merci!
0