I want to store data in the created file, but my code stores binary language in the file instead. Can anyone help me to store a string?
import java.io.*;
import java.util.*;
class WriteToFileExample {
public static void main(String args[]) {
try {
// Create file
FileWriter fstream = new FileWriter("out.txt");
BufferedWriter out = new BufferedWriter(fstream);
Scanner sc = new Scanner(System.in);
System.out.println("enter name");
int a = sc.nextInt();
out.write(a);
out.close();
} catch (Exception e) {
//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}