+ 4
data creation in java
whats the error with this code.it didnt work on my ide https://code.sololearn.com/cix8kTQyckq2/?ref=app https://code.sololearn.com/cix8kTQyckq2/?ref=app
2 Réponses
+ 2
For first one
Scanner sc=new Scanner(System.in); //object of Scanner class
System.out.print("Enter the file name: ");
String name=sc.nextLine(); //variable name to store the file name
try (FileOutputStream fos = new FileOutputStream(name, true)){
System.out.print("Enter file content: ");
String str=sc.nextLine()+"\n"; //str stores the string which we have entered
byte[] b= str.getBytes(); //converts string into bytes
fos.write(b); //writes bytes into file
//close the file
System.out.println("file saved.");
fos.close();
}
catch(Exception e)
{
System.out.println(e.toString());
}
+ 1
didnt work too cuma tekin Topuz