sc.nextLine(); // clear bufferrScanner sc = new Scanner(System.in);
System.out.print("Enter age: ");
int age = sc.nextInt();
sc.nextLine();
System.out.print("Enter name: ");
String name = sc.nextLine(); import static java.lang.System.out;
out.println("Hello, You!"); // this will workpublic class Main {
...
}
public class Animal {
...
}public class Main {
...
}
class Animal {
...
}FileWriter: Writes directly to file, character by character.
BufferedWriter: Uses internal buffer (8KB default), writes in chunks.
FileWriter is simpler for single writes.
BufferedWriter is faster for many writes (e.g., loops, large data).
FileWriter → write("text\n")
BufferedWriter → write("text\n") or newLine()