Bug 238 : Exported applications don't load files correctly
Last modified: 2007-02-03 09:25




Status:
RESOLVED
Resolution:
INVALID -
Priority:
P2
Severity:
normal

 

Reporter:
Ricard
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2005-12-05 21:09
Do the following:
1 - Create a file called "whatever.dude" in the data folder of the applet
2 - Fill in the file with some characters
3 - Run the following code inside pde -> a green circle shows up
4 - Export to application and run the code -> a red circle shows up (the
file isn't found correctly)

[code]
String filepath = "whatever.dude";
File file;
byte b[];

void setup(){
size(200,200);
smooth();
background(255);
stroke(0);

b = loadBytes(filepath);
}

void draw(){
background(255);
translate(width/2, height/2);

if(b!=null){
fill(0,255,0);
ellipse(0,0,50,50);
}else{
fill(255,0,0);
ellipse(0,0,50,50);
}
}
[/code]

the following code, doesn't work either (it's what I use in my library,
since I need accesing the file with a RandomAccessFile instead of a byte[]):

[code]
String filepath = "whatever.dude";
File file;

void setup(){
size(200,200);
smooth();
background(255);
stroke(0);

filepath = dataPath(filepath);
file = new File(filepath);
}

void draw(){
background(255);
translate(width/2, height/2);

if(file.exists()){
fill(0,255,0);
ellipse(0,0,50,50);
}else{
fill(255,0,0);
ellipse(0,0,50,50);
}
}
[/code]
Additional Comment #1 From fry 2005-12-07 06:29
the first example works fine for me.. at least on windows, you didn't
specify what platform you're on. if you're on linux you should download rev
0098.

for the second item, you'll need to create a data folder yourself based on
what dataPath() is giving you, because you can't get a RandomAccessFile out
of a jar file.