Hello
Someone know how to specify the path of file.
Because I have a problem to resolve the exercise
Thanks a lot
package fr.codegym.task.task15.task1525;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.File;
/*
Fichier dans un bloc statique
*/
public class Solution {
public static List<String> lines = new ArrayList<>();
public static void main(String[] args) {
String src_path = "\\src\\main\\java";
String filePath = new File("").getAbsolutePath();
String fullPath = filePath + src_path + Statics.FILE_NAME;
System.out.println(fullPath);
BufferedReader reader = null;
String line = null;
try {
reader = new BufferedReader(new FileReader(fullPath));
while((line = reader.readLine()) != null) {
System.out.println(line);
lines.add(line);
}
} catch(FileNotFoundException fne) {
fne.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// System.out.println("size lines reaeded : " + lines.size());
System.out.println(lines);
}
}