fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. ArrayList<String> data = new ArrayList<>(Arrays.asList("Перваая строка", "Вторая строка", "третья строка"));
  14. write("file.txt", data);
  15. }
  16.  
  17.  
  18. public static void write(String fileName, ArrayList<String> data) throws IOException {
  19. File file = new File(fileName);
  20.  
  21. try {
  22. if(!file.exists()){
  23. file.createNewFile();
  24. }
  25.  
  26. FileWriter writer = new FileWriter(file.getAbsoluteFile(), true);
  27. BufferedWriter bufferWriter = new BufferedWriter(writer);
  28.  
  29. try {
  30. for (String string : data) {
  31. bufferWriter.write(string);
  32. bufferWriter.newLine();
  33. }
  34. } finally {
  35. bufferWriter.close();
  36. }
  37. } catch(IOException e) {
  38. throw new RuntimeException(e);
  39. }
  40. }
  41. }
Runtime error #stdin #stdout #stderr 0.12s 320576KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.RuntimeException: java.io.IOException: Permission denied
	at Ideone.write(Main.java:38)
	at Ideone.main(Main.java:14)
Caused by: java.io.IOException: Permission denied
	at java.io.UnixFileSystem.createFileExclusively(Native Method)
	at java.io.File.createNewFile(File.java:1012)
	at Ideone.write(Main.java:23)
	... 1 more