-5

i try to copy the content of a file created in eclipse to other one and it gives me an error here is the code

package applitfichiertext;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;

public class Litfichiertext {

    public static void main(String[] args) throws Exception {
    File f=new File("note.txt");
    FileReader fr=new FileReader(f);
    File f2=new File("copie.txt");
    FileWriter fw=new FileWriter(f2);
    int a; //correspond au code acsii de reader ..c est à dire ce qu on n a lu dans le fichier
    while((a=fr.read()) !=-1) //la methode read donne le int du code ascci et si le filereader ne contient plus de donner il va returner -1
    {
        fw.write(a);;
    }
    fw.close();
    fr.close();
    }

}`

And the error:

Exception in thread "main" java.io.FileNotFoundException: note.txt (Le fichier spécifié est introuvable)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileReader.<init>(Unknown Source)
    at applitfichiertext.Litfichiertext.main(Litfichiertext.java:12)
Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78
Sunset
  • 9
  • 2
  • 2
    Did you read the error mesage? It tells you exactly what's wrong: "note.txt (Le fichier spécifié est introuvable)". – Jesper Sep 28 '14 at 07:07

3 Answers3

1

I believe your new to java and your error is "note.txt" doesnt exist. but like most new people you have it wrong place. Here is screen shot from eclipse to to where to have it.

it sits in your root java project directory and not in the src folder

enter image description here

smushi
  • 701
  • 6
  • 17
0

The error says note.txt File Not Found. solution: Keep your note.txt and copie.txt in same directory where your project is saved. OR Give the absolute path of both files. e.g. In Linux:

File f=new File("/home/shani/MyPrograms/MyFiles/note.txt");
File f2=new File("/home/userName/MyCopiedFiles/copie.txt");

Hope this will help you.

Programmer
  • 878
  • 2
  • 11
  • 24
0

The exception clearly tells you that it cannot find the file "note.txt". If you are sure that you have the file but the program fails to locate it then the best option is to print the path of the file "note.txt" from your code and then check the file in that path.

System.out.println(f.getAbsolutePath());

This will print the absolute path and then check for the file in your system in that path manually. This will help you to understand where actually your code is trying to locate your file.

Niru
  • 732
  • 5
  • 9