Writing lists inside object to files

Hi mates!
I have objects , each of those objects contains to arraylists .
what is the best way to write those lists to files in the hard drive ?
i need to write each of the objects one by one but im not sure rather there is an easy solution to this situation.
or ill just have to do all the dirty work myself :\
thank you.

As stated, your question is too vague to be capable of an answer.I'm not sure. I think OP should search for serialisation.

Similar Messages

  • During writing for archiving object FI_MKKDOC, file is not getting created

    Hi Experts,
    I am new to archiving concept & have one archiving object FI_MKKDOC which i have to complete as soon as possible.
    In this i have done all the basic settings & when i am excuting the transaction after putting production variant & scheduling it as immediate with LP01 printer.Job is finished successfully but in the log there is no message for any file creation. I have checked AL11 transaction also, no file is getting generated. Please help, we have configured the logical file ARCHIVE_GLOBAL_PATH and ARCHIVE_DATA_FILE.

    dont you have a spool file for this archiving job? This should usually list errors that prevented an item from beeing archived, and if nothing was archived, then no file exists.
    When you define a variant for the write step, then select full detailed log in the lower part of the selection screen, especially if it is the first time that you archive with this object.
    Further, please read the docu behind the blue info button in the selection screen. This tells you the sequence you have to use for the archiving as well as other important details.

  • List of object

    How to find the list of objects in the file. Example. we have two directory under jdbc directory i.e AAA and BBB. Under AAA directory, I have store two objets ( DataSource Object). Now I can find find out both the objects without knwing the name of object.
    Basically , how to list the objects under file system.

    http://java.sun.com/products/jndi/tutorial/basics/naming/list.html

  • Tag files, Lists, and object typing

    I'm passing a list of objects to a custom tag, created via a tag file.
    I can access object properties in the jsp page like this -
    <c:out value="${listOfItems[0].property}" />
    but inside the tag it doesn't work. It understands that its being passed a list and the number of items in the list but not the type of objects in the list. I think I need to declare the type of object that the list is returning but I'm unsure of th jstl way of doing this.
    advice?
    thanks

    JSTL uses introspection/reflection to call methods/access properties.
    It doesn't have to know the type of object in the list.
    How are you accessing this object in your tag file? Using EL again? That should work fine. If you use java/scriptlet code then you will need to cast the object.
    Have you declared the attribute that is being passed in? What type are you expecting? Default is String unless you specify otherwise.

  • Distribute eps objects with file list and quantity

    Hello everyone,
    Here's a script i wrote so I share it for the contribution.
    Here's my purpose. Every year, for a customer of our company, we have to print several description plates for their products. They give us about 30 or more texts, traduced in about 7 languages, and an excel file with quantities that each retail seller of each country do want to receive.
    We print these aluminium plates on a uv cured ink printing machine which have a table dimension of about 60x40cm. Preparing manually every files of 60x42cm to print was way too much time devouring, so i wrote that script.
    Before running this script you have to create a folder with your text files in eps, and create a new document with the dimension you want.
    Don't hesitate if you want more precisions with the process.
    #target illustrator
    #targetengine session
    This script allows you to import EPS files as linked files. It distributes them and centers the all according to the dimension of the artboard of your document, then it saves the file.
    You can define everything in the start list : target folder, basename of the destination files, how much objects per sheet you want, the roation if necessary, spacing between each objects, number of culumn for the distribution.
    If you want to distribute a number of objects that is bigger thant the limit of objects per sheet, the script reports the remaining in a new sheet after saving the previous one.
    The first 2 arrays contains the filenames to use in the source folder and their respective quantity.
    var doc = app.activeDocument;
    doc.rulerOrigin = [0,0];
    var xtimes = 0;
    var countName;
    var folder;
    var folder2;
    //var folder = 'C:\\Documents and Settings\\Administrateur\\Bureau\\BBB\\';
    // array for filenames
    var listEx=new Array (
    "File1.eps",
    "File2.eps",
    "File3.eps",
    // array for quantity for each filenames
    var listqte=new Array (
    15,
    8,
    19,
    //-------------UI CODE------------
    var win = new Window ("dialog");
    win.alignChildren = "left";
    // ------Folders selection panel
    var foldPanel = win.add("panel");
    foldPanel.alignChildren = "right";
    // source folder for files
    var panelGrp1 = foldPanel.add("group");
    var btnSource = panelGrp1.add("button",undefined,"Source Folder :");
    var txtSource = panelGrp1.add("edittext",undefined);
    txtSource.characters = 40;
    btnSource.onClick = function()
        folder2 = Folder.selectDialog ("Select Source folder..."); // get the source folder
        txtSource.text = folder2.fsName; // show the file Path here
    // destination folder
    var panelGrp2 = foldPanel.add("group");
    var btnSave = panelGrp2.add("button",undefined,"Save Folder :");
    var txtSave = panelGrp2.add("edittext",undefined);
    txtSave.characters = 40;
    btnSave.onClick = function()
        folder = Folder.selectDialog ("Select Destination folder..."); // get the source folder
        txtSave.text = folder.fsName; // show the file Path here
    // Base name for destination files
    var panelGrp3 = foldPanel.add("group");
    panelGrp3.alignment = "left";
    var bfn = panelGrp3.add("statictext",undefined,"Basename of target file :");
    var txtbfn = panelGrp3.add("edittext",undefined,"Description plates - UK");
    txtbfn.characters = 20;
            // other parameters
            var grp = win.add("group");
            grp.alignChildren = "left";
            grp.orientation = "column";
            // counter
            var wincount = grp.add("group");
            var textcount = wincount.add("edittext",undefined,0);
            textcount.characters=2;
            wincount.add("statictext",undefined,"Start count");
            //Limit number of placeditems to distribute in one file
            var winlimit = grp.add("group");
            var textlimit = winlimit.add("edittext",undefined,0);
            textlimit.characters=2;
            winlimit.add("statictext",undefined,"Limit");
            //number of Columns for the distribution
            var wincolon = grp.add("group");
            var textcolon = wincolon.add("edittext",undefined,0);
            textcolon.characters=2;
            wincolon.add("statictext",undefined,"Nb of columns");
            // Spacing values between each objects in mm
            var winspace = grp.add("panel",undefined,"Spacing in mm");
            winspace.orientation = "row";
            winspace.add("statictext",undefined,"X");
            var Xspace=winspace.add("edittext",undefined,0);
            Xspace.characters=7;
            winspace.add("statictext",undefined,"Y",undefined,0);
            var Yspace=winspace.add("edittext");
            Yspace.characters=7;
            // rotation angle
            var winrotate = grp.add("group");
            var textangle = winrotate.add("edittext",undefined,0);
            textangle.characters=3;
            winrotate.add("statictext",undefined,"Rotation in °");
    // Dropdownlist of presets   
    var winPreset =grp.add ("dropdownlist", undefined, [ "Description plates","Trapezes plates","-","Perso"]);
    winPreset.onChange = function ()
        switch (winPreset.selection.text)
                    case "Description plates":
                            textlimit.text=8;
                            textcolon.text=4;
                            Xspace.text=6.4;
                            Yspace.text=27;
                            textangle.text=0;
                            break;
                    case "Trapezes plates":
                            textlimit.text=18;
                            textcolon.text=6;
                            Xspace.text=9;
                            Yspace.text=9;
                            textangle.text=0;
                            break;
                    case "Perso":
                            textlimit.text=0;
                            textcolon.text=0;
                            Xspace.text=0;
                            Yspace.text=0;
                            textangle.text=0;
                            break;
    //winPreset.selection=1;
    var runBT=grp.add("button",undefined,"Run !");
    runBT.onClick = function()
        win.close();
        moteur();
    win.show();
    //--------------------End of UI CODE----------------
    //---------------------------------fonction  Placement of objects
    function place()
        var paddingx = parseFloat(Xspace.text)*2.834;        //spacing in mm between each column (for a value in points just suppress the *2.834)
        var paddingy = parseFloat(Yspace.text)*2.834;        //spacing in mm between each line
        var gridCols = textcolon.text;                            // number of columns
        var newGroup = doc.groupItems.add();
        var sel = doc.placedItems;
        // set the position of the first element, assuming that the group of all elements are centered  in X and Y  in the artboard
        var originX = (doc.width - ((doc.width - ((sel[0].width * gridCols) + (paddingx) * (gridCols-1)))/2))-sel[0].width
        var originY =((doc.height - (( sel[0].height * (textlimit.text/gridCols) ) +  (  paddingy*( (textlimit.text/gridCols)-1 )  )))/2)+sel[0].height
        var currentX= originX
        var currentY = originY
        for(var e=0, slen=sel.length;e<slen;e++)       
                //   :::SET POSITIONS:::
                sel[e].top = currentY;
                sel[e].left = currentX;
                //  :::DEFINE X POSITION:::
                currentX += -(sel[e].width + paddingx);
                if((e % gridCols) == (gridCols - 1))
                        currentX =  originX
                        //  :::DEFINE Y POSITION:::
                        currentY  += sel[e].height+paddingy;
                // ::Add to group
                sel[e].moveToBeginning (newGroup );
                redraw()
    //----------------------function Save
    function sauve()
        var fich =  txtbfn.text;    //Basename of the destination file
        // embed elements (for my case these are eps placeditem files)   
        for (var i = doc.placedItems.length-1; i >= 0; i-- )
                app.activeDocument.placedItems[i].embed();
        // draw a rectangle with the dimensions of the artboard and centered to it, with no fill color neither stroke color
        doc.rulerOrigin = [0,0];  // rulers to the origin
        var artboardRef = doc.artboards[0];
        // read dimensions oh the artboard to position therectangle
        var top=artboardRef.artboardRect[1] ;
        var left=artboardRef.artboardRect[0];
        var width=artboardRef.artboardRect[2]-artboardRef.artboardRect[0];
        var height=artboardRef.artboardRect[1]-artboardRef.artboardRect[3];
        var rect = doc.pathItems.rectangle (top, left, width, height);   
        rect.stroked = false;
        rect.filled = false;
        countName ++;
        // when several files are saved, the ten first files are numbered like this : 01, 02, 03... instead of 1,2,3
        var countName2 = countName;
        if (countName<=9) { countName2 = ("0" + countName)};
        if (xtimes != 0) // saves in eps, basename of file + number of times to repeat if necessary (it's to avoid to save several but identical files. For ex. if i have an object to print 100 times and i place 50 objects per file, the mention "2 times" will be mentionned in the name of the destination file )
                var dest= new File(folder + '/' + fich + ' ' + countName2 + ' - ' + xtimes + ' times' + '.eps');
        else
                var dest= new File(folder+ '/' + fich + ' ' + countName2 + '.eps') ;
        var options = new EPSSaveOptions();
        options.preview  = EPSPreview.None;
        //options.compatibility = Compatibility.ILLUSTRATOR14;
        //options.overprint = PDFOverprint.DISCARDPDFOVERPRINT
        //options.embedAllFonts = false;
        //options.includeDocumentThumbnails = false
        doc.saveAs(dest, options);
    //-------------------- function moteur
    function moteur()
        var limite = textlimit.text;            // max number of objects to distribute in one sheet
        var couchangl = textangle.text;    // rotation angle of the element
        //--------------Searches and signals if there is missing files in the source folder. If so, the script stops and displays which files are missing
        var miss=new Array();
        for (var i=0,len1=listEx.length;i<len1;i++)
            var myfile = new File(folder2+'/'+listEx[i]);
            if (myfile.exists==false)
                    miss.push(listEx[i]);
        if (miss.length != 0)
                alert (miss.length+" missing files : "+"\r"+miss.join(", "+"\r")+"\r"+"\r"+" Please correct and try again");
                return;
        //--------------end of  verification
    var start = new Date();        // starts chrono
    countName = textcount.text;    // start of the counter to number the name of the file to save
        //-------------disctribution of the object on the sheet
        for (var i=0,howmuch = 0,len1=listEx.length;i<len1;i++)
            for (var j =0; j<listqte[i];j++)
                    if (howmuch==0)
                            if ((listqte[i]-j)/limite>=2) //activate "xtimes" if quantity is twice or more bigger than "limit"
                                    xtimes = parseInt ((listqte[i]-j)/limite);
                                    j += limite*(xtimes-1);
                    myfile = new File(folder2+'/'+listEx[i]);
                    var  thisPlacedItem = doc.placedItems.add();
                    thisPlacedItem.file = myfile;
                    // rotate if necessary
                    if (couchangl !=0) thisPlacedItem.rotate(couchangl);
                    howmuch ++;
                    if (howmuch == limite)
                            place();
                            sauve();
                            doc.pageItems.removeAll();
                            howmuch = 0;
                            xtimes = 0;
    place();
    sauve();
    redraw();
    alert("time spent : "+((new Date() - start)/1000)+" secondes");

    Hello,
    The Windows Desktop Perfmon and Diagnostic tools forum is to discuss performance monitor (perfmon), resource monitor (resmon), and task manager, focusing on HOW-TO, Errors/Problems, and usage scenarios.
    As the question is off topic here, I am moving it to the
    Where is the Forum... forum.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book:
    Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • Writing Objects to File

    I have a number of records contained in a vector. Having trouble writing these records to a file. Even trying to write one record, as below, is throwing an exception. The Student class implements serializable and the method main throws IOException
    public  void saveRecords()
              try
                   FileOutputStream outStream = new FileOutputStream ("StudentRecord.dat");
                   ObjectOutputStream objOutStream = new ObjectOutputStream (outStream);
                   objOutStream.writeObject (student.elementAt(1));
                   objOutStream.flush();
                   objOutStream.close();
              } // end try
              catch (Throwable e)
                   System.out.println ("Error Writing File");
              } // end catch
         } // end saveRecords                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Thanks.
    I've sorted out the write part. The problem was that a student record object consisted objects of other classes, Name, Address, Course etc. All classes had to implement serializable before I could write the student objects to a file.
    Now having trouble with the reloading though. I've input 3 records which were successfully saved. However, on attempting to load these, I get an EOFexception. If I subsequently perform an enquiry on the records after attempting the read operation, records 1 and 3 are accessible but not record 2. Why should I get an EOFexception after 2 of 3 records Here's the code.
    public  void loadRecords ()
              try
                   FileInputStream inStream = new FileInputStream ("StudentRecord1.dat");
                   ObjectInputStream objInStream = new ObjectInputStream (inStream);
                   do
                   student.addElement((PGStudent)objInStream.readObject());
                             } while (objInStream.readObject() != null);
              } // end try
              catch (Throwable e)
                   System.out.println ("Error Reading File" + e.toString());
              } //  end catch
         } // end loadRecords
         public  void saveRecords()
              try
                   FileOutputStream outStream = new FileOutputStream ("StudentRecord1.dat");
                   ObjectOutputStream objOutStream = new ObjectOutputStream (outStream);
                   Enumeration enum = student.elements();
                   while(enum.hasMoreElements())
                        objOutStream.writeObject (enum.nextElement());
                   objOutStream.flush();
                   objOutStream.close();
              } // end try
              catch (Throwable e)
                   System.out.println ("Error Writing File" + e.toString());
              } // end catch
         } // end saveRecords

  • Plain file writing vs. Object writing

    Hi,
    I've a question about the use of object serialization when it comes to file io. Suppose I've written a binary tree datastructure, which is a pretty complex one. I've filled the tree with many object and now I want to be able to save the tree for later use. I could design some file format for the tree. But I could also use object serialization and write the whole tree object to file using the ObjectOutputStream. This makes it a lot easier.
    I also could write a simple preferences object (a static class with static Strings, which define my preferences) to a file, without saving the preferences using some file format.
    Now my question is: is object serialization meant for these types of things? Is this a good way of using it, or, for example, are the files going to be larger than necessary?
    Thank you!
    Jeroen

    Serialization will give you a pretty compact file. Not neccesarily the smallest possible file, but you would need to spend some time and effort creating aformat that yields smaller files, and there's not much space to gain this way.
    Serialization is fine when you never want to read the file with a program that's not written in java. Because reading a serialized file using a non-java program would mean implementing the code to parse and understand the encdings for the java object format and the java primitive types.
    Serialization pretty much prevents you from doing meaningsfull inspection of your data using less, grep or a text editor. If you want to be able to do this, then use a custom format that's built for readibily with such tools. It can still be pretty compact.

  • Writing Objects to file using Externalizable

    Hi,
    I'm trying to write an object to file. My sample code is:
    public class Junk implements Externalizable{
    private static java.util.Random generator = new java.util.Random();
    private int answer;
    private double[] numbers;
    private String thought;
    public Junk(String thought) {
    this.thought = thought;
    answer = 42;
    numbers = new double[3+ generator.nextInt(4)];
    for (int i=0; i<numbers.length; i++) {
    numbers[i] = generator.nextDouble();
    public void writeExternal(ObjectOutput stream) throws java.io.IOException {
    stream.writeInt(answer);
    stream.writeBytes(thought);
    for(int i=0; i< numbers.length; i++) {
    stream.writeDouble(numbers);
    public void readExternal(ObjectInput stream) throws java.io.IOException {
    answer = stream.readInt();
    String thought = stream.readUTF();
    and the class with main() is:
    package MyTest;
    import java.io.*;
    public class SerializeObjects {
    public SerializeObjects() {
    public static void main(String args[]) {
    Junk obj1 = new Junk("A green twig is easily bent.");
    Junk obj2 = new Junk("A little knowledge is a dangerous thing.");
    Junk obj3 = new Junk("Flies light on lean horses.");
    ObjectOutputStream oOut = null;
    FileOutputStream fOut = null;
    try {
    fOut = new FileOutputStream("E:\\FileTest\\test.bin");
    oOut = new ObjectOutputStream(fOut);
    obj1.writeExternal(oOut);
    //obj2.writeExternal(oOut);
    } catch (IOException e) {
    e.printStackTrace(System.err);
    System.exit(1);
    try {
    oOut.flush();
    oOut.close();
    fOut.close();
    } catch(IOException e) {
    e.printStackTrace(System.err);
    System.exit(1);
    The output I get in test.bin contains some junk ascii codes. The only item that is written correctly in the file is the string.
    Is there anyway I can write correct data into a file?
    My output needs to be a readable text format file.
    Can anyone help please?

    obj1.writeExternal(oOut);This should be
    oOut.writeObject(obj1);However,
    The output I get in test.bin contains some junk ascii
    codes. The only item that is written correctly in the
    file is the string.If you don't want 'junk' don't use Externalizable and ObjectOutputStream at all, just use PrintStream/PrintWriter.println().

  • Help me to solve writing object to file ?

    what's the happen ? when I write object to file ?
    My error is : java.io.NotSerializableException : Sun.awt.image.ToolkitImage
    What do I do to expect this error ?
    Please help me
    Thanks Very much

    you need to use ObjectInputStream and ObjectOutput Stream, you can write to file or read from file through readObject and write object.
    try this..!!

  • Writing java object into file

    Dear Experts,
    What is the best way to write java objects into file
    1. Using Object Output Stream
    or
    2.Using ByteArray OutputStream
    with Thanks
    Panneer

    Dear Experts,
    What is the best way to write java objects into file
    1. Using Object Output Stream
    or
    2.Using ByteArray OutputStream
    with Thanks
    PanneerWhat do you mean or? Because I would assume the contents of the byte array stream is coming from an ObjectOutputStream.
    Or do you mean to use some sort of buffering...

  • Embed Animated Flash Objects (*.swf file) in Oracle Forms.

    Hello All,
    To Embed Animated Flash Object (Shockwave *.swf File) in Oracle Forms, Please Follow the Steps Below.
    1. Draw "ActiveX Control" Item on Canvas with the Name "OCXITM".
    2. Select "ActiveX Control" Item & Go to its Properties (By Pressing F4).
    3. Select "ShockwaveFlash.ShockwaveFlash" in "OLE Class" Property of "ActiveX Control" Item.
    4. Come again to the Canvas.
    5. Right Click on "ActiveX Control" Item, Select "Insert Object...".
    6. In Control Type List, Select "Sockwave Flash Object" and Press "OK".
    7. On Canvas, Select "ActiveX Control" Item, Go to "Program" Menu, Select "Import OLE Library Interfaces...".
    8. Select All "Method Package(s)" & "Event Package(s)" for "ShockwaveFlash.ShockwaveFlash.X" & Press "OK".
    9. Go to "Object Nevigator" (By Pressing F3) & Expand "Program Unit" to verify that the Packages are Successfully Imported.
    10. Compile All the Objects (By Pressing "Ctrl+Shift+K").
    11. In "WHEN-NEW-FORM-INSTANCE" Trigger Write the Below Code.
    ** Author   : Muhammad Waseem Haroon                        *
    ** Dated    : 07-Apr-2005                                   *
    ** Purpose  : To Call Macromedia Flash Object (*.swf File)  *
    ** Module   : Logo                                          *
    DECLARE
         oleitm OLEOBJ;
    BEGIN
         oleitm := :item('OCXITM').INTERFACE;
         ShockwaveFlash_IShockwa_0.Movie(oleitm,'d:\movie.swf');--it can be dynamic.
    END;12. Compile, Save & Run Your Form.... and... See the Beauty.
    Thanks & Regards
    Muhammad Waseem Haroon
    [email protected]
    [email protected]
    [email protected]

    Mark Striekwold did an effort to put flash into forms
    http://mark-oradev.blogspot.com/2010/02/flash-inside-oracle-forms.html
    http://mark-oradev.blogspot.com/2010/02/flash-test-inside-oracle-forms-part-2.html
    http://mark-oradev.blogspot.com/2010/04/flash-test-inside-oracle-forms.html

  • Writing and loading Object

    Hello, I've been trying to save and load back in an Object File by using Object Serialization and ObjectOutputStream and ObjectInputStream. Everything works without casting any exceptions except when I load the fiel back in, it is null. I don't know why. I am actually trying to load a certain Class (which I named SaveGUI) that I have created and that contains many different Objects within itself and they are all Serializable. Now, to use the method readObject(), I guess the object has to be an instance of class Object so I tried extending SaveGUI to Object, It still didn't work.
    Can anyone give me some hints on what the problem could be?
    This is some of the code:
    FileDialog d = new FileDialog(GUI.this, "Save GUI State", FileDialog.SAVE);
    d.show(); // display the dialog and block until answered
    String filename = d.getFile(); // Get the user's response
    if (filename != null) {           // If user didn't click "Cancel."
    try {
    // Create the necessary output streams to save the Object.
    File f = new File(d.getDirectory(), filename); // Create a file object
    ObjectOutputStream out = new ObjectOutputStream(
    new java.util.zip.GZIPOutputStream(
    new FileOutputStream(f))); // Save objects
    out.writeObject((SaveGUI)saveGUI); // Write the entire Object.
    out.flush(); // Always flush the output.
    out.close(); // And close the stream.
    // Print out exceptions.
    catch (IOException ioe) { System.out.println("I/O Exception in file writing: "+ioe); }
    // Open up a dialog for the user to choose the file
    FileDialog d = new FileDialog(GUI.this, "Load a Saved GUI State", FileDialog.LOAD);
    d.show(); // display the dialog and block until answered
    String filename = d.getFile(); // Get the user's response
    if (filename != null || (filename.length() != 0)) {    // If user didn't click "Cancel."
    try {
    // Create the necessary input streams to load the GUI.
    File f = new File(d.getDirectory(), filename); // Create a File object
    ObjectInputStream in = new ObjectInputStream(
    new java.util.zip.GZIPInputStream(
    new FileInputStream(f))); // Read Object.
    SaveGUI obj = (SaveGUI)in.readObject(); // Assign Object.
    //in.close(); // And close the stream.
    // Print out exceptions.
    catch (IOException ioe) { System.out.println("I/O Exception in file loading: "+ioe); }
    public class SaveGUI extends java.lang.Object implements java.io.Serializable {
    public SaveGUI() {}
    Vector xAxisDataTable = new Vector(); // For each Frame there is a x-Axis DataTable
    Vector yAxisDataTable = new Vector(); // for each x-Axis column there is a y-Axis DataTable
    Vector titlexAxis = new Vector(); // The title of the xAxis (Vector of Strings)
    Vector titleyAxis = new Vector(); // (Vector of Strings)
    Vector plotsRecord = new Vector(); // Plotting Records of columns in x-Axis List (PlotRecord-s)
    Vector plotsOptions = new Vector(); // Plotting Options, for each layout frame (PlotOptionsFrame)
    }

    I solved it, don't worry

  • Net.sf.jasperreports.engine.JRException: Error loading object from file : C

    I started using JasperReports for my web application report generation. I'm using JSPs for web development.
    I created a .jrxml file using iReport and used the following code to generate the report.
    try {
              JasperDesign jasperDesign = JRXmlLoader.load("C:\\tomcat\\webapps\\web\\JSP\\reports\\samples\\pmm-final.jrxml");
              JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
    // Second, create a map of parameters to pass to the report.
              Map parameters = new HashMap();
              parameters.put("Title", "JasperReport");
    // Third, get a database connection
              Connection conn = null;
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              conn=DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=C:/tomcat/webapps/db1/db1.mdb");
    // Fourth, create JasperPrint using fillReport() method
              JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
                                  parameters, conn);
    // You can use JasperPrint to create PDF
              //JasperExportManager.exportReportToPdfFile(jasperPrint, "C:\\tomcat\\webapps\\web\\JSP\\reports\\TestReport.pdf");
              JasperExportManager.exportReportToHtmlFile(jasperPrint, "C:\\tomcat\\webapps\\web\\JSP\\reports\\TestPMM.html");
              JRXlsExporter exporter = new JRXlsExporter();
              exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
              exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "C:\\tomcat\\webapps\\web\\JSP\\reports\\TestPMM.xls");
              exporter.exportReport();
    // Or to view report in the JasperViewer
              //JasperViewer.viewReport(jasperPrint);
    } catch (JRException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
    } catch (SQLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
    The above pmm-final.jrxml uses a subreport 'top.jasper'. Error being thrown while loading top.jasper file. Error is as follows.
    java.io.InvalidClassException: net.sf.jasperreports.engine.base.JRBaseReport; lo
    cal class incompatible: stream classdesc serialVersionUID = 604, local class ser
    ialVersionUID = 606
    at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
    at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:86
    at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLo
    ader.java:236)
    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubre
    port.java:295)
    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:
    340)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageBand(JRVert
    icalFiller.java:1224)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVe
    rticalFiller.java:353)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRV
    erticalFiller.java:205)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVertic
    alFiller.java:119)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:
    613)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:
    483)
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:77
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillMa
    nager.java:248)
    at org.apache.jsp.JSP.UserGuide_jsp._jspService(org.apache.jsp.JSP.UserG
    uide_jsp:74)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
    .java:325)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
    95)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
    alve.java:214)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
    alve.java:178)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
    ava:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
    ava:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
    ve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
    a:148)
    at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:306)
    at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
    at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)
    at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.ja
    va:675)
    at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
    ool.java:684)
    at java.lang.Thread.run(Unknown Source)
    NESTED BY :
    java.io.InvalidClassException: net.sf.jasperreports.engine.base.JRBaseReport; lo
    cal class incompatible: stream classdesc serialVersionUID = 604, local class ser
    ialVersionUID = 606
    at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
    at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:86
    at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLo
    ader.java:236)
    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubre
    port.java:295)
    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:
    340)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageBand(JRVert
    icalFiller.java:1224)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVe
    rticalFiller.java:353)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRV
    erticalFiller.java:205)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVertic
    alFiller.java:119)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:
    613)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:
    483)
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:77
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillMa
    nager.java:248)
    at org.apache.jsp.JSP.UserGuide_jsp._jspService(org.apache.jsp.JSP.UserG
    uide_jsp:74)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
    .java:325)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
    95)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
    alve.java:214)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
    alve.java:178)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
    ava:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
    ava:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
    ve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
    a:148)
    at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:306)
    at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
    at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)
    at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.ja
    va:675)
    at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
    ool.java:684)
    at java.lang.Thread.run(Unknown Source)
    NESTED BY :
    net.sf.jasperreports.engine.JRException: Error loading object from file : C:\tom
    cat\webapps\web\JSP\reports\samples\top.jasper
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:90
    at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLo
    ader.java:236)
    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubre
    port.java:295)
    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:
    340)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageBand(JRVert
    icalFiller.java:1224)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVe
    rticalFiller.java:353)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRV
    erticalFiller.java:205)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVertic
    alFiller.java:119)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:
    613)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:
    483)
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:77
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillMa
    nager.java:248)
    at org.apache.jsp.JSP.UserGuide_jsp._jspService(org.apache.jsp.JSP.UserG
    uide_jsp:74)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
    .java:325)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
    95)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
    alve.java:214)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
    alve.java:178)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
    ava:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
    ava:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
    ve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
    a:148)
    at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:306)
    at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
    at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)
    at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.ja
    va:675)
    at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
    ool.java:684)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.InvalidClassException: net.sf.jasperreports.engine.base.JRBas
    eReport; local class incompatible: stream classdesc serialVersionUID = 604, loca
    l class serialVersionUID = 606
    at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
    at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:86
    ... 33 more
    Anyone pls help. It's bit urgent. Thanks.

    I was using iReport v0.5.0 and it uses jasperreports-0.6.7.jar (v0.6.7) of
    JasperReports. I compiled and i deployed my application in BEA weblogic server. I got the error listed below. Only after i saw your
    response explaining that iReport was the issue, i checked the iReport lib directory and found this version of jasperreport jar.
    iReport creates a java source file which is used to a jasper file.
    iReport will link in the v0.6.7 version of jasperReports. When you
    deploy your web application it will recognize this version through the compiled jasper file and give you the InvalidClassException, even
    though you only have one jasperReport jar deployed with your war file.
    The way i fixed this problem was to create my web application with the
    jasperreport jar comes with iReport.
    Thanks for mentioning iReport.
    Christopher
    Error:
    Caused by: java.io.InvalidClassException: net.sf.jasperreports.engine.base.JRBas
    eReport; local class incompatible: stream classdesc serialVersionUID = 607, local class serialVersionUID = 10002
    at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:463)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1521)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1435)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1521)
    ...

  • Include and call an .exe file inside my jar file

    Hi.
    I want to include an exe file and call it inside my jar file. this is the code.
    InputStream is = getClass().getResourceAsStream("/native/my.exe");
              int[] line = new int[is.available()];
              File myFile = File.createTempFile("my","exe");
              myFile.deleteOnExit();
              myFile.setExecutable(true);
              FileOutputStream out = new FileOutputStream(myFile.getAbsolutePath());
              int i = 0;
              int c;
              while((c=is.read()) != -1){
                   line=c;
                   i++;
              is.close();
              for(int j= 0;j<line.length;j++)
                   out.write(line[j]);
              out.close();
    So i store it in my temp folder. Than i run
    String myFileLocation = myFile.getAbsolutePath();
    p = rt.exec(myFileLocation);
    Everything goes fine, but the behaviour of the .exe file is not the same. I mean when i run the commands
    PrintWriter writer = new PrintWriter(p.getoutputStream());
    writer.println("command");
    the behaviour is not the same. What goes wrong.

    But to load the xml file I need to create a File objectIf this is true then you will not be able to load the XML file, since a jar entry is not a File object and cannot be represented as one.
    However if you get rid of whatever it is that loads your XML file and replace it by more standard JAXP processing, you should be able to parse an InputStream that reads from the jar entry. You know how to get that so it should not be a problem.

  • Directory listing from a JAR file

    Hi,
    I want to know how i can get a list of files in a certain directory located inside a jar file.
    Thanks

    Programmatically, you need to parse the JAR with the help of java.util.zip.
    From the command prompt, you can do it with "jar -t archive.jar"

Maybe you are looking for