i m trying to code for sorting strings,taking input from text file.When i m trying to specify a file for this program is gives me FileNotFoundExcetion i m unable to understand why? even i tried to get file path by writing code for that,in the screenShoot u can see that path is correct but the program is still giving me ERROR
here is thet Screenshort https://app.box.com/s/qytu1d9xlm0vcb6atz42
here is my code
public static void main(String[] args) throws FileNotFoundException, IOException {
ArrayList<String> row1 = new ArrayList<>();
FileWriter writer;
try {
String filename = "1.txt";
String finalfile = "";
String workingDir = System.getProperty("user.dir");
String your_os = System.getProperty("os.name").toLowerCase();
if (your_os.indexOf("win") >= 0) {
finalfile = workingDir + "\\" + filename;
} else if (your_os.indexOf("nix") >= 0 || your_os.indexOf("nux") >= 0) {
finalfile = workingDir + "/" + filename;
} else {
finalfile = workingDir + "{others}" + filename;
}
System.out.println("Final filepath : " + finalfile);
File file = new File(finalfile);
if (file.createNewFile()) {
System.out.println("Done");
} else {
System.out.println("File already exists!");
}
} catch (IOException e) {
e.printStackTrace();
}
try (BufferedReader reader = new BufferedReader(new FileReader("finalfile"))) {
String s;
while ((s = reader.readLine()) != null) {
row1.add(s);
}
Collections.sort(row1);
writer = new FileWriter("output.txt");
for (String s1 : row1) {
writer.write(s1 + "\n");
}
reader.close();
writer.close();
} catch (Exception e) {
System.out.print("Error : " + e);
}
}