I'm fairly new to Java. I was trying to add "List:" to the beginning of a new text file if it doesn't exist. Instead, the text file is blank, with the input below a line of blank space.
File hi = new File("hi.txt");
try{
if(!hi.exists()){
System.out.printf("\nCreating 'hi.txt'.");
hi.createNewFile();
String hello = "List:";
new FileWriter(hi).append(hello);
}
else{
System.out.printf("\nWriting to 'hi.txt'");
}
FileWriter writeHere = new FileWriter(hi, true);
String uling = "hi";
writeHere.append(uling);
writeHere.close();
}
//error catching
catch(IOException e){
System.out.printf("\nError. Check the file 'hi.txt'.");}