Not deleting .txt file for some reason
code: import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter Path (dont forget to escape characters!):"); String path = scan.nextLine(); File file = new File(path); try{ boolean isGood = file.createNewFile(); if (isGood){ FileWriter write = new FileWriter(path); System.out.println("Write to file:"); write.write(scan.nextLine()); write.close(); System.out.println("Content in file after writing to it:"); Scanner read = new Scanner(file); if (read.hasNextLine()){ System.out.println(read.nextLine()); } System.out.println("Would You like to delete it? 'yes' or 'no'"); String yesOrNo = scan.next(); boolean delete = yesOrNo.equalsIgnoreCase("yes") ? true : false; if (delete){ if (file.delete()){ System.out.println("File has been deleted!"); }else{ System.out.println("Couldnt delete file for somereason..."); } }else{ System.out.println("File is NOT deleted!"); } }else{ System.out.println("File already exists!"); } }catch(IOException e){ e.fillInStackTrace(); } } }