RE: parsing txt file - seems unparsable
I reckon you'll be needing a Java CFX then. Seemed like a fun 5 minute project so here ya go. - import com.allaire.cfx.*; import java.io.*; public class cfReadTxtFile implements CustomTag{ public void processRequest( Request request, Response response ) throws Exception { if ( !request.attributeExists("filename") || !request.attributeExists("variable") ) { throw new Exception("Missing attributes, filename and variable are required."); } String filename = request.getAttribute( "filename" ); String variable = request.getAttribute( "variable" ); String fileContent = ""; try { BufferedReader in = new BufferedReader(new FileReader(filename)); String str; while ((str = in.readLine()) != null) { fileContent = fileContent + str + System.getProperty("line.separator"); } in.close(); } catch (IOException e) { } response.setVariable( variable, fileContent); } } --- Call it like so... Tested and works perfectly on CF5 I'll mail you the source and the compiled CFX off list aswell. Craig. -Original Message- From: Stephenie Hamilton [mailto:[EMAIL PROTECTED] Sent: 06 October 2003 14:20 To: CF-Talk Subject: Re:parsing txt file - seems unparsable Tried this on CF5, and received this error: Unhandled System exception ! Failed to create JavaVM. JNI_CreateJavaVM returned error code JNI_ERR (this may indicate an unrecognized option string) which comes from line: action=""> any ideas? BTW, using cffile in CFMX to read the file works great, it doesn't choke on the null char. Too bad we don't have MX yet on our corporate servers (sigh). ~~ Stephenie >This is better though. > > >action=""> > > >action=""> > > > >line = ""; >while ( isDefined("line") ){ > line = jBRobj.readLine(); > if ( isDefined("line") ) { > writeoutput(line & "#chr(13)#"); > } >} >jBRobj.close(); > > > >Seems as soon as we reach EOF, jBRobj.readLine() returns null (expected) >and variable 'line' is no longer defined, quite handy in this case. > > _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
Re: parsing txt file - seems unparsable
IMHO this little square making trouble might be an ASCII null character. A null character is a byte with 0 value. Although it is a standard character in the ASCII code, CF will treat it as an end of string. That would explain why your text gets truncated. So you might check if indeed there are null characters in your file, and if yes, why are they there and if it would be possible they do not get there. If you can't prevent null characters, then you should look if you can treat your file as a binary object. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: parsing txt file - seems unparsable
If you're still having trouble, instead of CFFILE, try this Now parse your file. H. ~~ Howard Owens Internet Operations Coordinator Ventura County Star / E.W. Scripps Co. www.venturacountystar.com [EMAIL PROTECTED] AIM: GoCatGo1956 ~~ > -Original Message- > From: Stephenie Hamilton [SMTP:[EMAIL PROTECTED] > Sent: Wednesday, October 01, 2003 9:19 AM > To: CF-Talk > Subject: parsing txt file - seems unparsable > > I am trying to use CFFILE to parse a text file, put the contents in a > var and then insert that into a db. > > However, the file only gets parsed halfway through the first line. I > couldn't at first figure out why it would stop. If I opened the file > in notepad, added a space, then deleted the space, the file would > then parse correctly. > > I then opened the file in wordpad and discovered that where the > parsing stops there is a little square that doesn't show up in > notepad, assuming some type of special character or something, but I > have no idea what. > If I manually delete the little square, then it parses fine (until it > runs into the one on the next line etc)... > > is there any way to get past this? I am beating my head against the > wall and can no longer even see straight... > > tia > Stephenie > > > _ > > [ Todays Threads [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: parsing txt file - seems unparsable
This is better though. action=""> action=""> line = ""; while ( isDefined("line") ){ line = jBRobj.readLine(); if ( isDefined("line") ) { writeoutput(line & "#chr(13)#"); } } jBRobj.close(); Seems as soon as we reach EOF, jBRobj.readLine() returns null (expected) and variable 'line' is no longer defined, quite handy in this case. -Original Message----- From: Craig Dudley Sent: 02 October 2003 13:30 To: CF-Talk Subject: RE: parsing txt file - seems unparsable This might help. action=""> action=""> line = " "; while ( len(line) ){ line = jBRobj.readLine(); writeoutput(line & "#chr(13)#"); } jBRobj.close(); -Original Message- From: Jerry Johnson [mailto:[EMAIL PROTECTED] Sent: 01 October 2003 19:19 To: CF-Talk Subject: Re:parsing txt file - seems unparsable Is this CF 5 or earlier? If so, it is probably actually a NULL chr(0) character. Notepad will get rid of it when you open and save the file. CF 5 and earlier have trouble with strings containing NULLs, since it uses NULLs to mark the end of strings (I think). The data is still in the string, but all of the output string functions stop at that character. Solution? I don't have one. This is where Java and Custom Tags come in handy. Jerry Johnson >>> [EMAIL PROTECTED] 10/01/03 02:08PM >>> This sounds line an end -f line or carriage return character (or both) Do a replace of each [chr(10) & chr(13); replace with white space or some marker for your illumination "~~~" or whatever ] in the variable and see if that helps. Are you SURE it's not in the database, as well? Just kicked down a line? >If i open the file in notepad, then save it (without making any >changes) it works fine. h...wonder how/if i can use cfexecute to >have notepad open the file and then save it? >other than that, i can't think of anything else... > >Steph _ [ Todays Threads _ [ Todays Threads [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: parsing txt file - seems unparsable
This might help. action=""> action=""> line = " "; while ( len(line) ){ line = jBRobj.readLine(); writeoutput(line & "#chr(13)#"); } jBRobj.close(); -Original Message- From: Jerry Johnson [mailto:[EMAIL PROTECTED] Sent: 01 October 2003 19:19 To: CF-Talk Subject: Re:parsing txt file - seems unparsable Is this CF 5 or earlier? If so, it is probably actually a NULL chr(0) character. Notepad will get rid of it when you open and save the file. CF 5 and earlier have trouble with strings containing NULLs, since it uses NULLs to mark the end of strings (I think). The data is still in the string, but all of the output string functions stop at that character. Solution? I don't have one. This is where Java and Custom Tags come in handy. Jerry Johnson >>> [EMAIL PROTECTED] 10/01/03 02:08PM >>> This sounds line an end -f line or carriage return character (or both) Do a replace of each [chr(10) & chr(13); replace with white space or some marker for your illumination "~~~" or whatever ] in the variable and see if that helps. Are you SURE it's not in the database, as well? Just kicked down a line? >If i open the file in notepad, then save it (without making any >changes) it works fine. h...wonder how/if i can use cfexecute to >have notepad open the file and then save it? >other than that, i can't think of anything else... > >Steph _ [ Todays Threads [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
Re: parsing txt file - seems unparsable
I've run into this before. CF is actually opening the file correctly, but there's a null character, and CF uses null terminated strings, so it sees that and thinks the string is done. At least, that's my best guess. I've never found a way to fix this in CF, unfortunately. --Ben Stephenie Hamilton wrote: > I am trying to use CFFILE to parse a text file, put the contents in a > var and then insert that into a db. > > However, the file only gets parsed halfway through the first line. I > couldn't at first figure out why it would stop. If I opened the file > in notepad, added a space, then deleted the space, the file would > then parse correctly. > > I then opened the file in wordpad and discovered that where the > parsing stops there is a little square that doesn't show up in > notepad, assuming some type of special character or something, but I > have no idea what. > If I manually delete the little square, then it parses fine (until it > runs into the one on the next line etc)... > > is there any way to get past this? I am beating my head against the > wall and can no longer even see straight... > > tia > Stephenie > > [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
Re: parsing txt file - seems unparsable
if you output the content of the file in your cf template (prior to db insert) does it display the whole thing? If so, are you using cfqueryparam? > I am trying to use CFFILE to parse a text file, put the > contents in a > var and then insert that into a db. > However, the file only gets parsed halfway through the > first line. I > couldn't at first figure out why it would stop. If I > opened the file > in notepad, added a space, then deleted the space, the > file would > then parse correctly. > I then opened the file in wordpad and discovered that > where the > parsing stops there is a little square that doesn't show > up in > notepad, assuming some type of special character or > something, but I > have no idea what. > If I manually delete the little square, then it parses > fine (until it > runs into the one on the next line etc)... > is there any way to get past this? I am beating my head > against the > wall and can no longer even see straight... > tia > Stephenie > ~~ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
parsing txt file - seems unparsable
I am trying to use CFFILE to parse a text file, put the contents in a var and then insert that into a db. However, the file only gets parsed halfway through the first line. I couldn't at first figure out why it would stop. If I opened the file in notepad, added a space, then deleted the space, the file would then parse correctly. I then opened the file in wordpad and discovered that where the parsing stops there is a little square that doesn't show up in notepad, assuming some type of special character or something, but I have no idea what. If I manually delete the little square, then it parses fine (until it runs into the one on the next line etc)... is there any way to get past this? I am beating my head against the wall and can no longer even see straight... tia Stephenie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]