We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Loading .txt (Read 1689 times)
Loading .txt
Apr 25th, 2005, 8:33pm
 
Is it possible to load a .txt file? I'm looking at the reference and I'm not seeing any clear option here. Am I missing something obvious?

Also, the text file I'm attempting to load is about 1500 K; will Processing be able to handle this?
Re: Loading .txt
Reply #1 - Apr 25th, 2005, 8:39pm
 
The function you need is loadStrings()
http://processing.org/reference/loadStrings_.html
(you would've had to change the viewing option on the reference page to 'complete' to see it)

As far as the size of the txt file - I'm not sure. Can't hurt to give it a try Wink
Re: Loading .txt
Reply #2 - Apr 25th, 2005, 8:47pm
 
Ethan wrote on Apr 25th, 2005, 8:39pm:
(you would've had to change the viewing option on the reference page to 'complete' to see it)


Nice! Thanks for the quick reply!
Re: Loading .txt
Reply #3 - Apr 25th, 2005, 11:37pm
 
for large files you might need to use openStream():
http://processing.org/reference/openStream_.html

it works well, but is not yet documented.
Re: Loading .txt
Reply #4 - May 23rd, 2005, 6:02am
 
While we are on the subject, can you explain to me why/if
loadStrings() and saveStrings() read and write to different
directories? I don't seem to be able to update a file...just make new ones in different directories...I find it confusing to say the least. I guess I need Reading and Writing 101. It also appears to act differently in the applet environment were I presumed, apparentely incorrectly, that any data files would be exported along with others in the jar and be as accessible..
Smiley
Re: Loading .txt
Reply #5 - May 23rd, 2005, 10:47am
 
I'm pretty sure data files are put in the jar as you expect - post back if I'm mistaken.

Actually, the fact that data files are bundled into the jar file is a very good reason not to save things in the same place as you load them from - I have a sketch which saves out 200Mb tiff images, and I don't want one of them ending up the jar file, let alone more!

If you're implementing a cache of some sort, or a way to save state, it's better to load and save somewhere else.
Re: Loading .txt
Reply #6 - May 23rd, 2005, 11:55pm
 
aye, tom's hit it on the head. files are read from the .jar, specifically the 'data' folder, and saved to the sketch folder. of course you can save to a subfolder as well, but you can only do that inside the environment, you can't use saveStrings() or whatever with an applet.
Re: Loading .txt
Reply #7 - Nov 29th, 2005, 9:17am
 
fry wrote on May 23rd, 2005, 11:55pm:
... . of course you can save to a subfolder as well, but you can only do that inside the environment, you can't use saveStrings() or whatever with an applet.


that's a pity actually .. i use export to generate a double-clickable jar (with a main() method) on os-x. saveStrings() get's a little confused when used from inside this jar .. it saves the files into a folder called "null" inside the applet-folder. i know this is not really a bug since i'm leaving the processing way, but i thought maybe future versions will use export to generate standalone apps ...

F

(oh, processing 0096 on 10.4.3)
Re: Loading .txt
Reply #8 - Nov 29th, 2005, 3:23pm
 
that's something else, and would be a bug. i only meant that applets couldn't use saveStrings() to somehow save up to the server.
Re: Loading .txt
Reply #9 - Nov 29th, 2005, 3:29pm
 
actually no, i just tested it and it works fine.

my guess is that you're not setting up your main() properly, so the applet folder isn't being set. you should be using:

static public void main(String args[]) {
 PApplet.main(new String[] { "yoursketchname });
}

if you don't you're on your own to make sure all the variables necessary for p5 stuff like saveStrings() works.
Re: Loading .txt
Reply #10 - Dec 1st, 2005, 8:58am
 
yeah i know you were talking about saving to a server, just thought it fits here ... and you're right i was not initializing PApplet correctly. thanks!

F
Page Index Toggle Pages: 1