>I want to do some process manipulation with CF and I know for example that
>Runtime.exec() should return the running processes. I have no idea how to
>run Java stuff from within CF, I know you can just don't know how.
>
>Are there any good resources on doing this sort of thing 'cause google isn't
>helping me much this time.
Its not all that difficult. You need to instantiate the java class like you
would a cfc and then take it from there, calling the various methods etc, again
similar to what you would with a cfc. Here's an example that gets a listing of
all files within a directory using the java.io.File class:
note target directory requires a fully qualified path to the directory.
<cffunction name="getDirectoryListing" output="false"
returntype="Array">
<cfargument name="targetDirectory" required="yes" type="string">
<cfset var directoryList =
createObject("java","java.io.File").init(arguments.targetDirectory).list()>
<cfreturn directoryList>
</cffunction>
Another example using two java classes to read a file line by line and output
it to an array:
<cffunction name="readFileContents" access="public" output="false">
<cfargument name="fileName" required="true" type="string">
<cfset var fileReader = createObject("java",
"java.io.FileReader")>
<cfset var lineReader =
createObject("java","java.io.LineNumberReader")>
<! --- fileReader and lineReader instantiate their respective
java classes--->
<cfset var thisLine = true>
<cfset var results = arrayNew(1)>
<! --- init the fileReader Class with the fully qualified path
to the file --->
<! --- note this version only requires the pathname --->
<! --- lineReader requires the fileReader object --->
<cfset fileReader =
fileReader.init(expandPath(arguments.filename))>
<cfset lineReader = lineReader.init(fileReader)>
<! --- loop over the file appending the file contents line by
line into an array --->
<! --- keep looping over the file until there is no more lines
--->
<cfloop condition='isDefined("thisLine")'>
<cfset thisLine = lineReader.readLine()>
<cfif isDefined("thisLine")>
<cfset arrayAppend(results,thisLine)>
</cfif>
</cfloop>
<! --- close the file and line readers --->
<cfset fileReader.close()>
<cfset lineReader.close()>
<cfreturn results>
</cffunction>
Anyhow there are some good resources out there for working with CF and java.
Ben Forta's Advanced CF book has a good couple of chapters on it.
hth,
larry
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Get the answers you are looking for on the ColdFusion Labs
Forum direct from active programmers and developers.
http://www.adobe.com/cfusion/webforums/forum/categories.cfm?forumid-72&catid=648
Archive:
http://www.houseoffusion.com/groups/CF-Community/message.cfm/messageid:245500
Subscription: http://www.houseoffusion.com/groups/CF-Community/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.5