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. // TODO 自動產生的方法 Stub
  13.  
  14. //Begin
  15. String dst = "c:\\test0001.txt";
  16. String orgstring2="c:\\";
  17. String orgstring3="c:\\";
  18. String teststr = "test0003.txt";
  19. String teststr3 = "test0006.txt";
  20. FileWriter fptr = new FileWriter(dst);
  21. BufferedWriter writer01 = new BufferedWriter(fptr);
  22. writer01.write(teststr, 0, teststr.length());
  23. writer01.flush();writer01.close();
  24.  
  25.  
  26. //test1
  27. System.out.println("orgstring2.length()");
  28. System.out.println(orgstring2.length());
  29.  
  30. System.out.println("teststr.length()");
  31. System.out.println(teststr.length());
  32.  
  33. for(int j=0; j<teststr.length() ;j++) {
  34. {orgstring2 += (teststr.charAt(j));}
  35. //System.out.println(teststr.charAt(j));
  36. //System.out.println(orgstring);
  37. }
  38. // System.out.println("END String");
  39. // System.out.println(orgstring2);
  40. System.out.println("orgstring2.length()");
  41. System.out.println(orgstring2.length());
  42.  
  43. FileWriter fptr2 = new FileWriter(orgstring2);
  44. BufferedWriter writer02 = new BufferedWriter(fptr2);
  45. writer02.write(orgstring2, 0, orgstring2.length());
  46. writer02.flush();
  47. writer02.close();
  48.  
  49.  
  50.  
  51.  
  52.  
  53. //Test3
  54. System.out.println("orgstring3.length()");
  55. System.out.println(orgstring3.length());
  56. System.out.println("teststr3.length()");
  57. System.out.println(teststr3.length());
  58.  
  59.  
  60. //Test3
  61. orgstring3 += teststr3;
  62. System.out.println("orgstring3");
  63. System.out.println(orgstring3);
  64. System.out.println("orgstring3.length()");
  65. System.out.println(orgstring3.length());
  66.  
  67.  
  68. //Test3
  69. FileWriter fptr3 = new FileWriter(orgstring3);
  70. BufferedWriter writer03 = new BufferedWriter(fptr3);
  71. writer03.write(orgstring3, 0, orgstring3.length());
  72. writer03.flush();
  73. writer03.close();
  74.  
  75. //END
  76. }
  77. }
Runtime error #stdin #stdout #stderr 0.07s 380160KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.io.FileNotFoundException: c:\test0001.txt (Permission denied)
	at java.io.FileOutputStream.open(Native Method)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
	at java.io.FileOutputStream.<init>(FileOutputStream.java:104)
	at java.io.FileWriter.<init>(FileWriter.java:63)
	at Ideone.main(Main.java:20)