Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Getting an external resource on persons computer and saving to it  (Read 1396 times)
0 Members and 1 Guest are viewing this topic.
Offline Sequalit

Junior Devvie





« Posted 2006-04-23 04:19:54 »

My problem is, I have a file, in a folder called res. now in that folder i have my application.properties file.

my program is running from a executable jar file, and that res folder IS NOT packaged in the jar(if it was i wouldnt be able to save the application.properties file.

how do i get the location of that folder, that is outside of the jar, and then if it doesnt exist, create it?

ive tried getClass().getClassLoader().getResource(""); but my program still throws up an error when its in jarmode...


heres my code if it helps

xstream is just a xml parser
Properties.class holds my variables

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
private void load(){
      xstream = new XStream();//create the stream
      xstream.alias("properties", Properties.class);
      URL propURL = null;
      propURL = getClass().getClassLoader().getResource("res/application.properties");//get the location(in the jar)
      System.out.println(propURL);
      String xml = "";

      try{
         File f = new File(propURL.toURI());//create file by the properties
         BufferedReader inProp = new BufferedReader(new FileReader(f));
         String m = "";
         System.out.println("Reading...");
         prop = (Properties)xstream.fromXML(inProp);//parse file into the class
         System.out.println("Read");
         inProp.close();
      }catch(Exception e){
         if(e.getMessage() == null){
            JOptionPane.showMessageDialog(null, "Application is corrupted, reinstall");
            System.exit(0);
                                                                                    //ive tried to create it here, cant figure it out

         }
         e.printStackTrace();
      }
      lastDir = new File(prop.getLastLoadFolder());
      urlLink.setText(prop.getLastUrl());
   }

while(gettingTired())
     crankOutMoreCode();
     if(asleep()){
          wakeUp();
          makeCoffee();
          chugCoffee();
     }
}

-Sequalit
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2006-04-23 18:35:10 »

Is this an Applet or a Java Webstart App?

If so then you CANNOT touch the user's filesystem in any way unless you are signed and the user grants permissions.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Sequalit

Junior Devvie





« Reply #2 - Posted 2006-04-24 03:14:43 »

its a executable jar, it can also be a java webstart with all permisions

either way will work.

while(gettingTired())
     crankOutMoreCode();
     if(asleep()){
          wakeUp();
          makeCoffee();
          chugCoffee();
     }
}

-Sequalit
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #3 - Posted 2006-04-24 04:39:42 »

Alright, if its not sandbox-limited then  just use java.io.File

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline harry@dayfamilyweb

Junior Devvie





« Reply #4 - Posted 2006-04-24 07:03:14 »

on windows File f = new File("C:/my folder/my_file.myfilesexstension");
Offline c_lilian

Senior Devvie


Projects: 1


Java games will probably rock someday...


« Reply #5 - Posted 2006-04-24 07:14:17 »

File userDir = new File(System.getProperty("user.home");
File myAppDir = new File(userDir,"myApp");
if (!myAppDir.exist()) myAppDir.mkdir();
// now you've got a clean app temp directory

Alternative (preferred) way for small files / properties: use java.util.prefs.Preferences class

And for untrusted JWS applications : javax.jnlp.PersistanceService

Lilian Smiley

Offline Sequalit

Junior Devvie





« Reply #6 - Posted 2006-04-24 14:40:17 »

thanks!

i ended up using the preferences class for this, since it is jus a small string. works perfectly.

if i ever was to store something much bigger (save game file) then id probably have to use that userDir//appDir

while(gettingTired())
     crankOutMoreCode();
     if(asleep()){
          wakeUp();
          makeCoffee();
          chugCoffee();
     }
}

-Sequalit
Offline Ask_Hjorth_Larsen

Junior Devvie




Java games rock!


« Reply #7 - Posted 2006-04-25 03:45:31 »

Please don't put stuff randomly into the user home, it's a mess! Better put it beside the .jar file...
Offline Mr_Light

Senior Devvie


Medals: 1


shiny.


« Reply #8 - Posted 2006-04-25 19:36:33 »

please put it in the user dir. configuration, save games etc belong to the user.

while me and you might have the luxury of our own pc others don't.
esp with games and key settings.

well non user orientated can be stuck in the classpath I suppose.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Ask_Hjorth_Larsen

Junior Devvie




Java games rock!


« Reply #9 - Posted 2006-04-25 21:04:28 »

At least let the user specify something which won't clog the user dir. Imagine if all programs did that...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Sequalit

Junior Devvie





« Reply #10 - Posted 2006-04-26 03:53:51 »

well see, that was my question in the very begginng

HOW DO I PUT IT NEXT TO THE JAR FILE?

i relaly never wanted to go the registry way, but everyon keeps saying too, and now you say to do what im asking , how od i do it?

while(gettingTired())
     crankOutMoreCode();
     if(asleep()){
          wakeUp();
          makeCoffee();
          chugCoffee();
     }
}

-Sequalit
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (33 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (65 views)
2014-11-07 19:57:14

TehJavaDev (70 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (83 views)
2014-11-03 06:22:04

CopyableCougar4 (82 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!