Thanks Loathe the isDefined() null test is better then causing errors
unnecessarily with EOF. They should update that blog.
I like your new spin but <cfscript> does not have any advantages over CFML
tags
because it all turns into a class anyway.
You can also do it in one liner like this:
<cfset reader = createObject("java",
"java.io.BufferedReader").init(createObject("java",
"java.io.FileReader").init("C:\top50HeldbyInsiders.txt"))>
<cfset line = reader.readLine()>
<cfloop condition="#IsDefined("line")#">
<cfoutput> #len(line)# #HTMLEditFormat(line)#</cfoutput><br>
<cfset line = reader.readline()> <!--- keeps the loop going here --->
</cfloop>
<cfset reader.close()>
My example does not look like it will loop but it does!
It's magic!
On 8/15/06, loathe <[EMAIL PROTECTED]> wrote:
>
> So here's what I'm going with so far:
>
> <cfscript>
> fileReader = createObject("java", "java.io.FileReader");
> result = fileReader.init("C:\uq_mpes_orgcurr_info.txt");
> reader = createObject("java", "java.io.BufferedReader");
> reader.init(fileReader);
>
> // counter for the loop
> totalRecords = 0;
>
> line = "";
>
> while(1){
> line = reader.readLine();
> if(not isDefined("line")){
> break;
> }
>
> // additional processing goes here
> totalRecords = totalRecords + 1;
> writeOutput(line & "<br />");
> }
>
> </cfscript>
>
> Others are doing a try/catch block in order to "catch" and let pass the
> EOF,
> as CF doesn't get that. I figured out I could do it with an isDefined()
> check instead, I think it's a bit cleaner.
>
> Now on to the real fun, talking to the mainframe on the other side :)
>
> > -----Original Message-----
> > From: loathe [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, August 15, 2006 10:40 AM
> > To: CF-Talk
> > Subject: RE: Java/CF Question
> >
> > I like that, it's all inline, no external classes to worry about.
> >
> > I might have to go with that.
> >
> > > -----Original Message-----
> > > From: Dan Plesse [mailto:[EMAIL PROTECTED]
> > > Sent: Monday, August 14, 2006 10:27 PM
> > > To: CF-Talk
> > > Subject: Re: Java/CF Question
> > >
> > > For my biotech stock searching program which hunts the NASDAQ for
> > winners
> > > I do a line by line reading using the above objects.
> > >
> > > here are some code stuff to play with
> > >
> > > <cfset java_io_StringReader = CreateObject("java", "
> java.io.StringReader
> > > ").init(cfhttp.filecontent)>
> > >
> > > <cfset java_io_BufferedReader = CreateObject("java",
> > > "java.io.BufferedReader
> > > ").init(java_io_StringReader)>
> > >
> > > <cfset java_io_BufferedReader.skip(find(">Market Cap (intraday):",
> > > cfhttp.filecontent))>
> > >
> > > I like to close things too
> > >
> > > <cfset java_io_BufferedReader.close()>
> > > <cfset java_io_StringReader.close()>
> > >
> > > Another program example :
> > >
> > > <cfset java_net_URL = createobject("Java", "java.net.URL").init("
> > > http://finance.yahoo.com/q?s=win.to&d=v1")>
> > > <cfset InputStreamReader = createobject("Java",
> > "java.io.InputStreamReader
> > > ").init(java_net_URL.getContent())>
> > > <cfset BufferedReader = createObject("Java", "java.io.BufferedReader
> > > ").init(InputStreamReader)>
> > >
> > >
> > > <cfset line = BufferedReader.readline()>
> > >
> > > <cfloop condition="#IsDefined("line")#">
> > > <cfoutput> #len(line)# #HTMLEditFormat(line)#</cfoutput><br>
> > > </cfloop>
> > >
> > > <!--- Close your BufferReader ---->
> > > <cfset BufferedReader.close()>
> > > <cfset InputStreamReader.close()>
> > >
> > > I think when it hits the EOF "line" becomes null and undefined and
> ends
> > > the
> > > loop.
> > >
> > >
> > >
> > >
> > >
> > >
> > > On 8/14/06, Mark Mandel <[EMAIL PROTECTED]> wrote:
> > > >
> > > > Just for some reading, here is a post on using a BufferedReader (so
> > > > you can read line by line)
> > > >
> > > > http://www.compoundtheory.com/?action=displayPost&ID=54
> > > >
> > > > You'll need to wrap it around your fileReader, but that should work
> > for
> > > > you.
> > > >
> > > > HTH
> > > >
> > > > Mark
> > > >
> > > > On 8/15/06, loathe <[EMAIL PROTECTED]> wrote:
> > > > > Well, in reality this has a dual goal.
> > > > >
> > > > > 1. Get me using more Java in my CF.
> > > > >
> > > > > And
> > > > >
> > > > > 2. Use the type 4 JDBC drivers to the DB2 mainframe to see how
> they
> > > > perform
> > > > > and are accessed and so forth.
> > > > >
> > > > > This is one little piece of a huge application, and I'm using it
> to
> > > get
> > > > my
> > > > > feet wet :)
> > > >
> > > >
> > > > --
> > > > E: [EMAIL PROTECTED]
> > > > W: www.compoundtheory.com
> > > >
> > > >
> > >
> > >
> >
> >
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:249857
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4