Erreur problem sur ficher pouvez vous m'aider

malek2212 Messages postés 18 Date d'inscription   Statut Membre Dernière intervention   -  
KX Messages postés 16761 Date d'inscription   Statut Modérateur Dernière intervention   -
Bonjour,
j'ai un problem sur un fichier
j'ai utilese la class Path et une liste pour mettre les chaque lign de ficher dans la liste

mais j'ai un problem que je n'ai pas comprais

Exception in thread "main" java.nio.file.NoSuchFileException: fileTest.txt
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(Unknown Source)
at java.nio.file.Files.newByteChannel(Unknown Source)
at java.nio.file.Files.newByteChannel(Unknown Source)
at java.nio.file.spi.FileSystemProvider.newInputStream(Unknown Source)
at java.nio.file.Files.newInputStream(Unknown Source)
at java.nio.file.Files.newBufferedReader(Unknown Source)
at java.nio.file.Files.readAllLines(Unknown Source)
at java.nio.file.Files.readAllLines(Unknown Source)
at paths.tpfile.main(tpfile.java:14)

et voila mon code
package paths;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

public class tpfile {

public static void main(String args[]) throws IOException
{
Path p=Paths.get("fileTest.txt");
List<String> lines=Files.readAllLines(p);


}
}

merci

1 réponse

KX Messages postés 16761 Date d'inscription   Statut Modérateur Dernière intervention   3 020
 
Bonjour,

Le message d'erreur est clair "NoSuchFileException: fileTest.txt"
Java n'a pas trouvé ton fichier...

Peut-être parce qu'il ne cherche pas le fichier au bon endroit.
Par défaut le répertoire est résolu en chemin relatif, affiches le en chemin absolu pour voir où il va le chercher.

System.out.println(p.toAbsolutePath());
0