+ 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

3rd Oct 2020, 2:29 PM
Dove
Dove - avatar
2 ответов
+ 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()); }
4th Oct 2020, 4:55 PM
cuma tekin Topuz
cuma tekin Topuz - avatar
+ 1
didnt work too cuma tekin Topuz
8th Oct 2020, 12:23 PM
Dove
Dove - avatar