Date Created: Sun 28-Aug-2011

Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/



    Jython File Handler Class


    class FileHandler :
    def __init__(self, fileName) :
    self.fileName = fileName
    return
    #endDef

    # a file exists if you can open and close it
    def exists(self):
    try:
    f = open(self.fileName)
    f.close()
    return True
    except:
    return False
    #endTry
    #endDef

    def writeText(self,text) :
    try :
    self.outputfile.write(text)
    except :
    print "ERROR writing text to file name: " + self.fileName
    #endTry
    return
    #endDef

    def open(self) :
    print "opening: " + self.fileName
    try :
    self.outputfile=open(self.fileName,'w')
    except :
    print "ERROR opening file name: " + self.fileName + " for writing!"
    #endTry
    print self.fileName + " was sucessfully opened"
    return
    #endDef

    def close(self) :
    print "closing: " + self.fileName
    try :
    self.outputfile.close()
    except :
    print "ERROR closing file name: " + self.fileName + "!"
    #endTry
    print self.fileName + " was sucessfully closed"
    return
    #endDef
    #endClass


    ==============

    Example of use....


    #Get handle to file
    myFh = fileHandler("c:\temp\output.txt")
    #open file for writing
    myFh.open()
    #Overwrites file as this is what we want
    myFh.writeText("this is some text 1")
    #close file as we have finished with it
    myFh.close()

    I have many WebSphere Jython example scripts being available here:
    http://www.themiddlewareshop.com/category/websphere-jython-examples/
    http://www.themiddlewareshop.com/category/websphere/websphere-application-server/jython/

    Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/


Steve Robinson - IBM Champion 2013

About Me

Steve Robinson has been working in IT for over 20 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware.

In January 2013, I was awarded the prestigous 'IBM Champion' accolade.


Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Other Categories