generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

(Java) Writing to a file problem

Previous Thread :: Next Thread 
PompeyTheGreat is not online. PompeyTheGreat
Joined: 10 Apr 2011
Total Posts: 5615
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 is not online. 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
PompeyTheGreat is not online. PompeyTheGreat
Joined: 10 Apr 2011
Total Posts: 5615
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 is not online. 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
PompeyTheGreat is not online. PompeyTheGreat
Joined: 10 Apr 2011
Total Posts: 5615
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
PompeyTheGreat is not online. PompeyTheGreat
Joined: 10 Apr 2011
Total Posts: 5615
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
PompeyTheGreat is not online. PompeyTheGreat
Joined: 10 Apr 2011
Total Posts: 5615
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
PompeyTheGreat is not online. PompeyTheGreat
Joined: 10 Apr 2011
Total Posts: 5615
05 Dec 2011 08:51 PM
Bump

## don't judge me ##
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 2 of 2Go to page: 1, [2] Prev
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image