|
| 05 Dec 2011 07:34 PM |
21 is
FileOutputStream menu = new FileOutputStream("C:\\Menus\\Menu for " + month + ".txt");
## don't judge me ## |
|
|
| Report Abuse |
|
|
Cenort
|
  |
| Joined: 20 Nov 2009 |
| Total Posts: 9679 |
|
|
| 05 Dec 2011 07:38 PM |
just saying = new File(Path) doesn't actually create a file on the computer
Right after you say new File put this code: if(!f.exists()){ f.createNewFile(); |
|
|
| Report Abuse |
|
|
|
| 05 Dec 2011 07:44 PM |
Exception in thread "main" java.io.IOException: Access is denied at java.io.WinNTFileSystem.createFileExclusively(Native Method) at java.io.File.createNewFile(Unknown Source) at GenerateMenu.main(menugenerator.java:21)
Is what I get when I add that. Would I need to import something?
## don't judge me ## |
|
|
| Report Abuse |
|
|
Merely
|
  |
| Joined: 07 Dec 2010 |
| Total Posts: 17266 |
|
|
| 05 Dec 2011 08:00 PM |
From my research, it appears you have to create a new directory first.
File file=new File(path); if(!file.exists()) file.mkdirs(); // or file.mkdir() |
|
|
| Report Abuse |
|
|
|
| 05 Dec 2011 08:06 PM |
Exception in thread "main" java.io.FileNotFoundException: C:\Menus\Menu for Dece mber.txt (Access is denied) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(Unknown Source) at java.io.FileOutputStream.<init>(Unknown Source) at GenerateMenu.main(menugenerator.java:29)
Still denied :-/
Line 29 is this:
FileOutputStream menu = new FileOutputStream("C:\\Menus\\Menu for " + month + ".txt");
## don't judge me ## |
|
|
| Report Abuse |
|
|
|
| 05 Dec 2011 08:09 PM |
Oh wait, it's creating the Menus folder, but instead of a text file, it creates another folder inside Menus. This is probably why I can't write to it :P
## don't judge me ## |
|
|
| Report Abuse |
|
|
|
| 05 Dec 2011 08:21 PM |
Ok I got it to create a text file, but it creates a folder also and leaves the text open. I can't delete it D:
How could I get it to create only the text file?
## don't judge me ## |
|
|
| Report Abuse |
|
|
| |
|
|
| 05 Dec 2011 09:55 PM |
File theFile = new File("C:/Menus/Menu%20for%20" + month + ".txt"); FileWriter fw; if (!theFile.exists()) { fw = new FileWriter("C:/Menus/Menu%20for%20" + month + ".txt", true); } else { fw = new FileWriter(theFile, true); } PrintWriter editor = new PrintWriter(fw);
// Try this and see what you come up with. I haven't worked with file IO for a while...
Cheers, -- AFF |
|
|
| Report Abuse |
|
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
|
| 05 Dec 2011 09:58 PM |
When you're done writing the files, close them.
menu.close();
---------- ~ pwendu46, the unicorn ~ |
|
|
| Report Abuse |
|
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
|
| 05 Dec 2011 09:59 PM |
Ignore that last comment. I didn't look at the source. :\
---------- ~ pwendu46, the unicorn ~ |
|
|
| Report Abuse |
|
|