Probleme fichier en java
Résolu
bouchrot
Messages postés
351
Date d'inscription
Statut
Membre
Dernière intervention
-
oxander25 -
oxander25 -
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
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:
- Probleme fichier en java
- Fichier bin - Guide
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Fichier epub - Guide
- Fichier rar - Guide