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.
IndexProgramming Questions & HelpSyntax Questions › File IO help needed
Page Index Toggle Pages: 1
File IO help needed (Read 1601 times)
File IO help needed
May 15th, 2010, 2:43am
 
Hello!
I just started using Processing, i want to know how to read a text file and print it's content?? i m loading file with loadStrings() but dont know how to print it... and also i want to know that how can i load a text from any other location rather than in skecth... for example "C:/programs files/test.txt"...

PLzz any help will be appreciated... Thank you.
Re: File IO help needed
Reply #1 - May 15th, 2010, 3:25am
 
To print how? On a printer? Or just with println()?
With the latter, just use a for () loop to iterate on the created array and println() each line[i].

Other location: just use the full path as you shown.
Re: File IO help needed
Reply #2 - May 15th, 2010, 8:29pm
 
PhiLho  wrote on May 15th, 2010, 3:25am:
To print how On a printer Or just with println()
With the latter, just use a for () loop to iterate on the created array and println() each line[i].

Other location: just use the full path as you shown.


Thanks for your response...

Sorry to bug you but can you plzz share the whole code? actually as i told u i am a newbie so em confused where will the content of the file will print? in the box which appears after compiling or in the Processing IDE.....

Actually my aim is to take input from the text file and use that input in arduino to blink desired LED or move servo motor... as this is my start thats y i just want to take input from text and just print it...
Re: File IO help needed
Reply #3 - May 15th, 2010, 8:38pm
 
Hey i did print it content by your help but after running the code it also give the error Array out of bound... i know that i am not giving the correct array size in for loop... but i want to know the function used to count the array length... like length.lines etc???
Re: File IO help needed
Reply #4 - May 15th, 2010, 8:50pm
 
Lolz i did print the contents too by using lines.lenght() method... but my path problem is still the same... i am giving loadStrings("c:\test.txt"); and it is showing me this error

"The file "c:      est.txt" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable."

the test file is out of the sketch folder and the test file is in c:\, what to do now??
Re: File IO help needed
Reply #5 - May 15th, 2010, 8:54pm
 
Yeah  Cheesy
this must be my lucky day... i did that also by using this pattern... "C:\\test.txt"  Grin
Thanks alot, and thanks for your help Grin
Re: File IO help needed
Reply #6 - May 16th, 2010, 12:37am
 
Quote:
The file "c:      est.txt" is missing or inaccessible


The problem with your original path was that \t represents a tab (in the same way that \n is a new line) - hence the error message with the \t missing and replaced by a tab.  In fact the backslash \ represents the beginning of an escape sequence - which allow you to insert special characters into a string (e.g. \" puts in a double-quote without closing the string parameter...).  But then of course the backslash itself needs to be escaped as follows: \\

For more info see 'escape sequences' on this page.
Re: File IO help needed
Reply #7 - May 16th, 2010, 1:57am
 
Oh thanks alot. Smiley
Page Index Toggle Pages: 1