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().

Similar Messages

  • Writing to a file using log4j

    Hi ,
    I am facing an issue in rolling out file on an hourly basis. I have a source file , say usagelog_date.log which records logging, then after an hour an hour I have to separate that file , give it a different name say usagelog_date.10.log , I copy the contents of the source file into the rolling file, and make that source file empty. But after making that file empty when I am writing to the file using some threads simultaneously, I get some blank characters first and only after that the logging starts, that increases the file size to a large extent.
    My java code which does this separation is as follows.
    package com.proquest.services.usage.helper;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.nio.channels.FileLock;
    import java.util.Calendar;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    public class UsageRotator {
         private Log scpLog = LogFactory.getLog("SCPLog");
         public String rotateAndReturnFilename(String rotationdate, String location) throws Exception {
              Calendar calendar = Calendar.getInstance();
              int hour_of_day = calendar.get(Calendar.HOUR_OF_DAY);
              String rotationalTime = ((hour_of_day < 10) == true) ? "0" + hour_of_day : "" + hour_of_day;
              String rotatedFileName = null;
              File usageLoggingLogFile = new File(location + "usagelogging." + rotationdate + ".log");
              if (usageLoggingLogFile != null && usageLoggingLogFile.exists()) {
                   File usageLoggingRotatedFile = new File(location + "usagelogging." + rotationdate + "." + rotationalTime + ".log");
                   copyFile(usageLoggingLogFile, usageLoggingRotatedFile);
    //copying the contents of source file to a rolling file
                   FileOutputStream fout = new FileOutputStream();
    // making the source file empty fout.flush();               
                   usageLoggingLogFile.setWritable(true);
                   boolean isEmpty = isFileEmpty(usageLoggingLogFile);
                   if(isEmpty)     
                        scpLog.info("Existing file has been empty so it's good to proceed for looging next occurances");
                   rotatedFileName = usageLoggingRotatedFile.getName();
                   scpLog.info("Log file has been rotated to "+rotatedFileName);
              } else {
                   throw new Exception("File rotation failed : UsageLogging file couldn't be found for the supplied date");
              return rotatedFileName;
         private void copyFile(File source, File destn) throws Exception {
              FileInputStream fis = new FileInputStream(source);
         FileOutputStream fos = new FileOutputStream(destn);
         try {
         byte[] buf = new byte[1024];
         int i = 0;
         while ((i = fis.read(buf)) != -1) {
         fos.write(buf, 0, i);
         catch (FileNotFoundException e) {
         throw new Exception("[ERROR] File copy failed");
         finally {
         if (fis != null) fis.close();
         if (fos != null) fos.close();
         private boolean isFileEmpty(File file) throws Exception {
              FileReader fr = new FileReader(file);
              BufferedReader br = new BufferedReader(fr);
              boolean isEmpty = true;
              while (br.readLine() != null) {
                   isEmpty = false;
              return isEmpty;
    And my log4j file with which I am writing is
    # Default is to send information messages and above to the console
    log4j.rootLogger = DEBUG, DailyLogFileAppender
    # Logger configurations
    #log4j.logger.com.proquest.services.usage=DEBUG, DailyLogFileAppender
    log4j.logger.com.proquest.services.UsageLog=INFO, UsageLogFileAppender
    # Appender configurations
    # Define an appender which writes to a file which is rolled over daily
    log4j.appender.DailyLogFileAppender = com.proquest.services.log.PqDailyRollingFileAppenderExt
    log4j.appender.DailyLogFileAppender.File = logs/usagelogging/usagelogging-error.log
    log4j.appender.DailyLogFileAppender.DatePattern = '.'yyyy-MM-dd
    log4j.appender.DailyLogFileAppender.Append = true
    log4j.appender.DailyLogFileAppender.layout = org.apache.log4j.PatternLayout
    log4j.appender.DailyLogFileAppender.layout.ConversionPattern=%d{ISO8601} %m%n
    log4j.additivity.com.proquest.services.usage = false
    log4j.additivity.com.proquest.services.UsageLog = false
    log4j.appender.UsageLogFileAppender = com.proquest.services.log.PqDailyRollingFileAppenderExt
    log4j.appender.UsageLogFileAppender.File = logs/usagelogging/usagelogging.log
    log4j.appender.UsageLogFileAppender.DatePattern = '.'yyyy-MM-dd
    log4j.appender.UsageLogFileAppender.Append = true
    log4j.appender.UsageLogFileAppender.layout=org.apache.log4j.PatternLayout
    log4j.appender.UsageLogFileAppender.layout.ConversionPattern=%d{ISO8601} %m%n
    Can somebody please suggest me what to do, as I have been badly deadlocked into the problem.
    Thanks
    Suman

    neoghy wrote:
    ... rolling out file on an hourly basis.
    And my log4j file with which I am writing is
    #  Default is to send information messages and above to the console
    log4j.rootLogger = DEBUG, DailyLogFileAppender
    # Logger configurations
    #log4j.logger.com.proquest.services.usage=DEBUG, DailyLogFileAppender
    log4j.logger.com.proquest.services.UsageLog=INFO, UsageLogFileAppender
    # Appender configurations
    #  Define an appender which writes to a file which is rolled over daily
    log4j.appender.DailyLogFileAppender = com.proquest.services.log.PqDailyRollingFileAppenderExt
    log4j.appender.DailyLogFileAppender.File = logs/usagelogging/usagelogging-error.log
    log4j.appender.DailyLogFileAppender.DatePattern = '.'yyyy-MM-dd
    log4j.appender.DailyLogFileAppender.Append = true
    log4j.appender.DailyLogFileAppender.layout = org.apache.log4j.PatternLayout
    log4j.appender.DailyLogFileAppender.layout.ConversionPattern=%d{ISO8601} %m%n
    log4j.additivity.com.proquest.services.usage = false
    log4j.additivity.com.proquest.services.UsageLog = false
    log4j.appender.UsageLogFileAppender = com.proquest.services.log.PqDailyRollingFileAppenderExt
    log4j.appender.UsageLogFileAppender.File = logs/usagelogging/usagelogging.log
    log4j.appender.UsageLogFileAppender.DatePattern = '.'yyyy-MM-dd
    log4j.appender.UsageLogFileAppender.Append = true
    log4j.appender.UsageLogFileAppender.layout=org.apache.log4j.PatternLayout
    log4j.appender.UsageLogFileAppender.layout.ConversionPattern=%d{ISO8601} %m%nCan somebody please suggest me what to do, as I have been badly deadlocked into the problem.I assume you mean [DailyRollingFileAppender ^apache^|http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/DailyRollingFileAppender.html]
    log4j.appender.DailyRollingFileAppender.DatePattern = '.'yyyy-MM-dd-HH

  • Problem writing object to file

    Hi everyone,
    I am creating an index by processing text files. No of files are 15000 and index is a B+ Tree. when all files processed and i tried to write it to the file it gives me these errors.
    15000 files processed.
    writing to disk...
    Exception in thread "main" java.lang.StackOverflowError
            at sun.misc.SoftCache.processQueue(SoftCache.java:153)
            at sun.misc.SoftCache.get(SoftCache.java:269)
            at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:244)
            at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1029)
            at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
            at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:380)
            at java.util.Vector.writeObject(Vector.java:1018)
            at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:585)
            at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:890)
            at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1333)
            at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
            at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
            at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1245)
            at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1069)
            at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
            at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:380)
            at java.util.Vector.writeObject(Vector.java:1018)
            at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:585)
            at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:890)
            at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1333)
            at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
            at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
            at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
            at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
            at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
            at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
            at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
            at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
            at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
            at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
            at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
            at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
            at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
            at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
            at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
            at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
            at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
            at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
            at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
            at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
            at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
            at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
            at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
    ..........can anyone point out the mistake im doing?
    thanks

    the B+ Tree is balanced and is perfectly working without writing to the file. and i am using default writeObject() method of ObjectOutputStream.
      try {
                                FileOutputStream   f_out   = new   FileOutputStream ("tree.idx");
                                ObjectOutputStream obj_out = new   ObjectOutputStream (new BufferedOutputStream (f_out));   
         for (int x = 0, l = files.length; x < l; x++) {
              ProcessTree(files[x].toString());
                    System.out.println("Writing main index to the disk...");
                    obj_out.writeObject (tree); 
                    obj_out.flush();
                    obj_out.close();
                    } catch (Exception e)
          System.out.println (e.toString ());
          System.out.println("Error Writing to Disk!");
        }

  • Writing into Excel file using PL/SQL and formatting the excel file

    Hi,
    I am writing into a excel file using PL/SQL and I want to make the first line bold on the excel. Also let me know if there are any other formatting options when writing into excel.
    Regards,
    -Anand

    I am writing into a excel file using PL/SQL
    Re: CSV into Oracle and Oracle into CSV
    check that thread or search in this forum...

  • Writing object to file

    My dilemma is i am wanting to write an arraylist to a specific folder within the package mounted in Netbeans. My only problem is I am running on a mac and cannot get to write to correct place. I have tried to use /.../file name etc. It works if i explicitly give the whole path but i do not want to do this as this app will need to transportable to other machines. Any help please.
    Thanks
    Chad

    I tried you suggestion and it works good for getting to the users home folder but I am wanting to contain the resource data file all within the same package. ie... Folder contains all .java files and any resource folders needed. I can get the resource just fine using getClass().getResourceAsStream() but when i write out i get errors. I am using
    Is there something like the getClass... that mimics writing out to files. I am also using a mac and only plan on distributing this to other macs only.
    Thanks
    Chad

  • Reading and Writing large Excel file using JExcel API

    hi,
    I am using JExcelAPI for reading and writing excel file. My problem is when I read file with 10000 records and 95 columns (file size about 14MB), I got out of memory error and application is crashed. Can anyone tell me is there any way that I can read large file using JExcelAPI throug streams or in any other way. Jakarta POI is also showing this behaviour.
    Thanks and advance

    Sorry when out of memory error is occurred no stack trace is printed as application is crashed. But I will quote some lines taken from JProfiler where this problem is occurred:
              reader = new FileInputStream(new File(filePath));
              workbook = Workbook.getWorkbook(reader);
              *sheeet = workbook.getSheet(0);* // here out of memory error is occured
               JProfiler tree:
    jxl.Workbook.getWorkBook
          jxl.read.biff.File 
                 jxl.read.biff.CompoundFile.getStream
                       jxl.read.biff.CompoundFile.getBigBlockStream Thanks

  • 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 data into files using VHDL Textio

    Hi 
    I was trying to write nos. from 1 to 8 into a text file using the below program.
    process
    type IntegerFileType is file of integer;
    file data_out: IntegerFileType ;
    variable fstatus: FILE_OPEN_STATUS;
    variable coun: natural:= 1;
    begin
    file_open(fstatus,data_out,"myfile.txt",write_mode);
    for i in 1 to 8 loop
    write(data_out, coun);
    coun := coun + 1;
    end loop;
    file_close(data_out);
    wait; -- an artificial way to stop the process
    end process;
    But getting the below attached result..
    Can you please help me out what could be wrong with the program.
    Thanks & regards
    Madhur

    Do you want the numbers in the file to be human readable ASCII?
    Then you'll need to convert your coun to a string. 
    declare another variable of type line (type access to string).
    do a write() to the line, then a writeline() to the file.
    natural'image(coun) will convert coun to a string.
    Google should help you find example code that will help.

  • Writing to a file using an applet?

    I'm trying to write to a .txt file using an applet. When I run the applet from JBuilder everything works perfectly, but when I run it from internet explorer I don't seem to be able to read or write from and to the file... Anyone has an idea? Is it possible to do that?

    Applets run on restricted security priveelege. Unless you sign your applet, you cant access the files from the applet.
    Go through this.. This might help you
    http://developer.java.sun.com/developer/technicalArticles/Security/Signed/

  • How to dynamicaly link multiple shared objects (.so files) using JNI

    Hi all,
    I recently started working on JNI where i suppose to call C application's .so files using JAVA. Existing C application is huge, it contains many .so files which are having dependencies with other .so files. My problem is when i call a function of one .so file it does not link with other .so files at run time and gives me error(undefined function as that function is implemented in other .so file).
    Can someone suggest me any solution for the same? I am a Java developer and don't have much knowledge about the C language.
    Any suggestion will be highly appreciated.

    jeet420 wrote:
    Hi all,
    I recently started working on JNI where i suppose to call C application's .so files using JAVA. Existing C application is huge, it contains many .so files which are having dependencies with other .so files. My problem is when i call a function of one .so file it does not link with other .so files at run time and gives me error(undefined function as that function is implemented in other .so file). That is not a Java/JNI problem.
    A shared library either uses an explicit link or dynamic link to other libraries.
    If the first then the OS will fail the load of the library if it can't find the dependency.
    If the second then the implementation (the developer) is responsible for correctly dealing with the problem.
    Again none of the above has anything to do with Java nor JNI.
    Nothing in Java nor JNI will help you to figure out the problem nor manage it.
    Two solutions.
    1. Be very careful in manually managing the laydown via an installer of all of the required libraries.
    2. Write code to verify that all libraries are found by the OS. This however still require manual steps as you must explicitly name the shared libraries in some way.
    ... and don't have much knowledge about the C language.Not a good situation. JNI assumes that you have quite a bit of knowledge about C and/or C++.

  • 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

  • Writing to a file using labview

    hello,
    so i wrote this vi to write some data to a text file and that part works correctly.
    the problem i'm having is that, it doesn't append to the file. so for each data point that it writes it requires a new file.
    in otherwords, if i need to write 10 data points the program prompts each time for 10 different file names.
    how do i resolve this so that the program will write all the 10 data points to one file, by appending each time.
    e.g. data points: 29.5, 34.2, 21.34, 543.2 ... etc
    i want something like this:
    29.5
    34.2
    21.34
    543.2
    etc
    thanks
    -r

    If the path is correctly wired, it should not prompt you for another file. Make sure you wire the path to a shift register so it is available the next time the "write charaters ..." is called.
    You can do the "exception" in many ways. Some examples:
    --Check if the file exists, and if so, append.
    --Use a shift register initialized by "false", then wire it to the append terminal. Feed a "true" to the shift register on the right.
    However, you should consider using some of the lower level file I/O and open the file only once, then keep writing data and close it only at the end. The high-level "write characters to file" would need to do a lot of extra work because whenever it is called it opens the file, writes/appends data, then
    closes the file again.
    LabVIEW Champion . Do more with less code and in less time .

  • Writing to a file using DataOutputStream

    the goal is to write an object named cd1 to a file data.dat using a method writeData.
    writeData is defined as:
    void writeData(DataOutputStream out), which writes an object, field y field to a DataOutputStream. (plus some other blah blah).
    so here's what I have so far (only pieces of code are posted)
    File dataFile = new File(ioDir, "data.dat");
                   dataFile.createNewFile();
                   DataOutputStream out1 = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(dataFile)));
                   cd1.writeData(out1);
         public void writeData(DataOutputStream out) {
              iWritten = true;
              try {
                   out.writeInt(iNumTracks);
                   out.writeBoolean(iWritten);
                   out.close();
              } catch (IOException xcp) {
                   System.out.println(xcp);
         }but when I open the file data.dat it seems to be totally empty, doesn't seem like anything gets written to it.

    have to check the file size ?
    the data you write to the file maybe not displayable on screen. example, all character/byte < 32

  • Problem writing to excel file using report generation toolkit

    hello everyone, i have this report generation toolkit... and i want to output DAQmx Analog I/P data on to an excel sheet. the DAQmx is programmed to collect 
    data at 3samples/sec. however, when i see the excel file that Report Generation Toolkit generates, the time stamp is updated every second instead of every 0.33sec. 
    can anyone please help me?  i am using the MS Office Report Express VI. 
    Now on LabVIEW 10.0 on Win7

    @All, I got rid of the express VI, decided to work on the custom low level VIs instead. however, i have a new problem now... 
    I have a case statement wherein, the user selects if he wants to start generating a report. once the program enters tat loop, the program speed reduces! 
    can anyone please tell me why is it happening? i ahve attached the vi... also another question.. in this VI, i am capturing the unwanted data into the graph as I am indexin the graph input. how can i make a logic 
    that the graph captures the data only when I am switching the CREATE REPORT button (which is in the while loop). is there a way that I can append the data to the graph without creating a new graph every iteration? please let me know
    thanks
    Now on LabVIEW 10.0 on Win7
    Attachments:
    Untitled 7.vi ‏75 KB
    Untitled 7.JPG ‏99 KB

  • Writing an XML file using a Servlet

    Hello, I'm trying to code a servlet that receives a POST from a HTTP and output its data to a XML file, the problem is that I get the following error:
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    XML document must have a top level element. Error processing resource 'http://localhost:8080/XMLSender/xmlsend'.
    I don't know what happens, because I'm NOT trying to show the content, just to save it, I post my code here so anyone can help me, please. Thanks in advance.
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class xmlsender extends HttpServlet
    public void service(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    ServletOutputStream salida = res.getOutputStream();
    res.setContentType("text/xml");
    String cadenanumero = req.getParameter("numero");
    String cadenaoperadora = req.getParameter("operadora");
    String cadenabody = req.getParameter("mensaje");
    String cadenashortcode = req.getParameter("shortcode");
    File f1 = new File("salida.xml");
    FileWriter writer = new FileWriter(f1);
    writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    writer.write("<root>");
    writer.write("<tlf>" + cadenanumero + "</tlf>");
    writer.write("<op>" + cadenaoperadora + "</op>");
    writer.write("<sc>" + cadenashortcode + "</sc>");
    writer.write("<body>" + cadenabody + "</body>");
    writer.write("</root>");
    writer.close();
    }

    Yes, in fact what I want is the file to be in the server, now, I modificated my code to the following:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class xmlsender extends HttpServlet
    public void service(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    ServletOutputStream salida = res.getOutputStream();
    res.setContentType("text/HTML");
    String cadenanumero = req.getParameter("numero");
    String cadenaoperadora = req.getParameter("operadora");
    String cadenabody = req.getParameter("mensaje");
    String cadenashortcode = req.getParameter("shortcode");
    File f1 = new File ("salida.xml");
    FileWriter writer = new FileWriter(f1);
    /*salida.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    salida.println("<root>");
    salida.println("<tlf>" + cadenanumero + "</tlf>");
    salida.println("<op>" + cadenaoperadora + "</op>");
    salida.println("<sc>" + cadenashortcode + "</sc>");
    salida.println("<body>" + cadenabody + "</body>");
    salida.println("</root>"); */
    salida.println("Finalizado");
    f1.createNewFile();
    writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    writer.write("<root>");
    writer.write("<tlf>" + cadenanumero + "</tlf>");
    writer.write("<op>" + cadenaoperadora + "</op>");
    writer.write("<sc>" + cadenashortcode + "</sc>");
    writer.write("<body>" + cadenabody + "</body>");
    writer.write("</root>");
    writer.close();
    It still do not create my file "salida.xml", still don't know why. Any help is welcome.

Maybe you are looking for

  • Error While Activating ODS in BW

    Hai Experts While Activating the ODS the following errors are occurs The creation of the export DataSource failed RFC connection to source system B3TCLNT800 is damaged ==> no Metadata upload Error when creating the export DataSource and dependent Obj

  • How to query opening balance for all customer or Vendor for an speci. date

    Hi, How to query opening balance for all customer or Vendor for an specific date? Example: put any date and query will show all customer/ Vendor  that date opening/current balance. Regards, Mizan

  • On windows xp i cant find my netgear router or set a wireless connection up

    when i go onto windows i cant get onto the internet. I have a wireless netgear router that works with mac os x but i cant set it up for the windows

  • "Downgrade" M93p MT to 32-bit Windows 7 pro

    I just bought a Lenovo ThinkCentre M93p MT and it comes with a 64 bit Windows 7 or Windows 8 (both are Pro). The problem is that this computer should run legacy software that the developer says runs "only on 32 bit Windows 7". I have downloaded a 32

  • Fast website development?

    I'm primarily a print designer, but more of my clients are requesting web-based solutions. I've designed about 10 websites total, but all of them were done with GoLive, for which I received professional training. Although I own Dreamweaver CS5, my wo