File writing in Java

Hello, I try to create and write a file from my java application, but I have some problems...
I can not write in it !! here is my code
File fichierDll = new File("e:\\fichierdll.txt");
try{
fichierDll.createNewFile();
FileWriter ecrireDll = new FileWriter(fichierDll);
ecrireDll.write(";DLL id list\n[DLL id]\nid1=213\n");
catch (IOException e){
System.out.println("Erreur cr�ation fichier Dll");          
The file is created, but it is empty !!
What is wrong??
Thanks Eric

Change it to this:
File fichierDll = new File("e:\\fichierdll.txt");
try{
// fichierDll.createNewFile(); - Remove this, it is unnecessary
FileWriter ecrireDll = new FileWriter(fichierDll);
ecrireDll.write(";DLL id list\n[DLL id]\nid1=213\n");
ecrireDll.flush();
ecrireDll.close();
catch (IOException e){
System.out.println("Erreur cr�ation fichier Dll");

Similar Messages

  • Need help writing a Java rule in PDF Forms

    I have created an invoice for my contractors via "forms", and in turn made each cell either a drop down list or "read only" field so they cannot change the rate of pay, etc.  Here is my issue...My first drop down cell is titled "Job Description".  When the contractor selects one of the 8 dropdown options within the Job Description field, I would like it to automatically fill in the hourly rate that is associated with that particular job description (or skill).  I currently have my "rate" cell as a drop down, and I want to make that a read only, and when you select the A1 position from Job Description, it will populate the "rate" field with the appropriate amount for that A1 rate.  I believe this can be done with writing some Java script, but I have never played with Java and I don't really have the time to teach myself.  If anyone can help with me a quick tutorial, or even the formula I should use, so that I can just plug and play, that would be super helpful.  If this is a time consuming issue, I would be interested in paying someone to do it for me. Thank you!

    Hi George,
    I was able to copy my data over to a fresh document, and now it works just fine....thank you so much for your insight and help!
    I have another question if you have a moment. 
    I am trying to do a simple calculation of start time and end time for my employees.  Do I need to do this via a javascript, and if so, what area in properties of the result field should I copy it to?  for the purpose of the script, the fields are as follows:
    DataField1 = start time
    DataField2 = end time
    DataField3 = total time
    I would like to use the h:MM tt format for my time fields if possible.
    I've attached a link to the file through my dropbox account, and you'll notice that I created three new fields at the top of the invoice just to test the time calculations before i mock up the whole document.
    Dropbox - Contractor Invoice Template (1).pdf
    Any help you can give me would awesome! 
    Thank you!!

  • How can I execute a batch file from my java program

    Hi,
    Can someone help me or direct me to a link,
    How can I execute a DOS batch file from my java program?
    Thanks

    You will need to grab a handle to the process's
    outputstream so u can see its output.The OP didn't mention any output from any batch file;
    nor any input for that
    matter,so lets not complicate matters here for now
    ok?Actually I think this is essential to see whether it works or not. It's either that or do some manual check to see whether it ran, which is not exactly elegant, and in some cases this may not be easier than simply writing the output stream code, or in fact it may be impossible to check manually.
    I'm sure it wasn't intentional that your post appeared to be bristling with attitude.

  • File Name in Java Map

    Hello,
    I want to add the time stamp in the file name in JAVA map.
    Actually we are directly writing the file on to the file system from Java map and also giving its output to other map.
    So we need when we write the file on the file system the file name should be ABC_timestamp.
    Can anyone help me how to do this in Java Map.
    Thanks and Regards
    Hemant

    Hi,
    >>>Actually we are directly writing the file on to the file system from Java map and also giving its output to other map.
    are you sure you want to do this?
    this is highly inadvisable as mappings do not support restarts and any error handling
    further more what if the mapping will crash but the file will be created?
    if you restart the mapping you will get a second file?
    I'd recomment not doing anything like that - maybe think about your scenario once more ?
    Regards,
    Michal Krawczyk

  • Nfs mount point does not allow file creations via java.io.File

    Folks,
    I have mounted an nfs drive to iFS on a Solaris server:
    mount -F nfs nfs://server:port/ifsfolder /unixfolder
    I can mkdir and touch files no problem. They appear in iFS as I'd expect. However if I write to the nfs mount via a JVM using java.io.File encounter the following problems:
    Only directories are created ? unless I include the user that started the JVM in the oinstall unix group with the oracle user because it's the oracle user that writes to iFS not the user that creating the files!
    I'm trying to create several files in a single directory via java.io.File BUT only the first file is created. I've tried putting waits in the code to see if it a timing issue but this doesn't appear to be. Writing via java.io.File to either a native directory of a native nfs mountpoint works OK. ie. Junit test against native file system works but not against an iFS mount point. Curiously the same unit tests running on PC with a windows driving mapping to iFS work OK !! so why not via a unix NFS mapping ?
    many thanks in advance.
    C

    Hi Diep,
    have done as requested via Oracle TAR #3308936.995. As it happens the problem is resolved. The resolution has been not to create the file via java.io.File.createNewFile(); before adding content via an outputStream. if the File creation is left until the content is added as shown below the problem is resolved.
    Another quick question is link creation via 'ln -fs' and 'ln -f' supported against and nfs mount point to iFS ? (at Operating System level, rather than adding a folder path relationship via the Java API).
    many thanks in advance.
    public void createFile(String p_absolutePath, InputStream p_inputStream) throws Exception
    File file = null;
    file = new File(p_absolutePath);
    // Oracle TAR Number: 3308936.995
    // Uncomment line below to cause failure java.io.IOException: Operation not supported on transport endpoint
    // at java.io.UnixFileSystem.createFileExclusively(Native Method)
    // at java.io.File.createNewFile(File.java:828)
    // at com.unisys.ors.filesystemdata.OracleTARTest.createFile(OracleTARTest.java:43)
    // at com.unisys.ors.filesystemdata.OracleTARTest.main(OracleTARTest.java:79)
    //file.createNewFile();
    FileOutputStream fos = new FileOutputStream(file);
    byte[] buffer = new byte[1024];
    int noOfBytesRead = 0;
    while ((noOfBytesRead = p_inputStream.read(buffer, 0, buffer.length)) != -1)
    fos.write(buffer, 0, noOfBytesRead);
    p_inputStream.close();
    fos.flush();
    fos.close();
    }

  • Object file handling giving java.io.StreamCorruptedException

    Hi All,
    I am storing and retriving objects from a file. but when i write multiple objects then while reading objects from the file its giving
    java.io.StreamCorruptedExceptionPlease advice. Here's the code
    import java.io.*;
    class Person implements Serializable{
         String name = null;
         int age = 0;
         public void setName(String name){
              this.name = name;
         public String getName(){
              return this.name;
         public void setAge(int age){
              this.age = age;
         public int getAge(){
              return this.age;
    public class ObjectFileRead{
         public static void main(String args[]){
         try{     
         *     Writing the objects to the file
              FileOutputStream out = new FileOutputStream("Person.dat",true);
              ObjectOutputStream objOutStream = new ObjectOutputStream (out);
              for(int i=0;i<5;i++){
                   Person p = new Person();
                   p.setName("MyName:1"+i);
                   p.setAge(10+i);
                   //System.out.println(p.getName());
                   //System.out.println(p.getAge());
                   objOutStream.writeObject (p);
              objOutStream.flush();
              objOutStream.close();
         *     Reading the objects fromt the file;
              FileInputStream inStream = new FileInputStream ("Person.dat");
              ObjectInputStream objInStream = new ObjectInputStream (inStream);
              try{
                   while(true){
                        Person p = (Person)objInStream.readObject();
                        System.out.println(p.getName());
                        System.out.println(p.getAge());
              }catch(EOFException e){
         }catch(Exception e){
              System.out.println(e);
    }

    The output of ObjectOutputStream starts with a header. Because you append to the file Person.dat you end up with multiple headers, but you only open one ObjectInputStream. One approach would be to create a new ObjectInputStream wrapping inStream after every 5 objects read. I suspect a better one (because it avoids the risk of ObjectInputStream doing read-ahead and buffering) is to replace the appending with reading the file and writing it out again followed by the new objects.

  • Is File handling in Java Swing possible?

    Hi I need to know whether file handling in Java Swing is possible or not?

    cents wrote:
    Thanks for ur answer.....Actually I just wanted to know whether "Reading from a file" and "Writing to a file" in Java Swing is possible or not?
    Edited by: cents on Mar 16, 2010 9:35 AMWhat did google tell you? Did you see anything interesting in the API?

  • Java.io.WriteAbortedException: writing aborted; java.io.NotSerializableEx

    <b>anyone can explain this
    i want to modify a value and hits this problem
    </b>
    [20070828 10:58:27:125] E [AppLog/MI/API/Services   ] java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.sap.ip.me.api.services.MEResourceBundle
    java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.sap.ip.me.api.services.MEResourceBundle
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1278)
         at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
         at com.sap.ip.me.api.services.IOUtils.readSerializedObjectFromFile(IOUtils.java:934)
         at com.sap.ip.me.api.services.IOUtils.readHashtableFromDirectory(IOUtils.java:835)
         at com.sap.ip.me.sync.InboundProcessorRegistryImpl.<init>(InboundProcessorRegistryImpl.java:66)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
         at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
         at java.lang.Class.newInstance0(Class.java:308)
         at java.lang.Class.newInstance(Class.java:261)
         at com.sap.ip.me.api.conf.Configuration.createInstanceForType(Configuration.java:512)
         at com.sap.ip.me.api.conf.Configuration.getSingletonInstanceForType(Configuration.java:457)
         at com.sap.ip.me.api.sync.InboundProcessorRegistry.<clinit>(InboundProcessorRegistry.java:78)
         at com.sap.ip.me.smartsync.core.SmartSyncRuntimeManager.initializeSmartSyncFramework(SmartSyncRuntimeManager.java:132)
         at com.sap.ip.me.core.FrameworkInitializer.initSmartSync(FrameworkInitializer.java:883)
         at com.sap.ip.me.core.FrameworkInitializer.initializeFramework(FrameworkInitializer.java:367)
         at com.sap.ip.me.core.FrameworkInitializer.main(FrameworkInitializer.java:126)
         at com.sap.ip.me.mdk.api.runtime.Start.startME(Start.java:139)
         at com.sap.ip.me.mdk.api.runtime.Start.main(Start.java:46)
    Caused by: java.io.NotSerializableException: com.sap.ip.me.api.services.MEResourceBundle
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
         at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
         at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
         at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
         at com.sap.ip.me.api.services.IOUtils.serializeObjectToFile(IOUtils.java:875)
         at com.sap.ip.me.api.services.IOUtils.saveHashtableToDirectory(IOUtils.java:801)
         at com.sap.ip.me.sync.InboundProcessorRegistryImpl.register(InboundProcessorRegistryImpl.java:285)
         at com.sap.ip.mi.systemnews.NewsImpl.create(NewsImpl.java:313)
         at com.sap.ip.mi.systemnews.StartListener.userLoggedOn(StartListener.java:24)
         at com.sap.ip.me.core.UserManagerImpl.fireLogon(UserManagerImpl.java:2283)
         at com.sap.ip.me.core.UserManagerImpl.logOnUser(UserManagerImpl.java:766)
         at com.sap.ip.me.core.UserManagerImpl.logOnUser(UserManagerImpl.java:744)
         at com.sap.ip.me.apps.jsp.LoginServlet.doHandleEvent(LoginServlet.java:274)
         at com.sap.ip.me.api.runtime.jsp.AbstractMEHttpServlet.doGetNotThreadSafe(AbstractMEHttpServlet.java:347)
         at com.sap.ip.me.api.runtime.jsp.AbstractMEHttpServlet.doGet(AbstractMEHttpServlet.java:689)
         at com.sap.ip.me.api.runtime.jsp.AbstractMEHttpServlet.doPost(AbstractMEHttpServlet.java:706)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at com.sap.ip.me.api.runtime.jsp.AbstractMEHttpServlet.service(AbstractMEHttpServlet.java:313)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
         at org.apache.tomcat.core.Handler.service(Handler.java:287)
         at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
         at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:806)
         at org.apache.tomcat.core.ContextManager.service(ContextManager.java:752)
         at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
         at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
         at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
         at java.lang.Thread.run(Thread.java:534)
    [20070828 10:58:27:968] E [AppLog/MI/API/Services   ] Problems while saving C:\Program Files\SAP Mobile Infrastructure\sync\inboundProcessors\1.value
    java.io.NotSerializableException: com.sap.ip.me.api.services.MEResourceBundle
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
         at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
         at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
         at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
         at com.sap.ip.me.api.services.IOUtils.serializeObjectToFile(IOUtils.java:875)
         at com.sap.ip.me.api.services.IOUtils.saveHashtableToDirectory(IOUtils.java:801)
         at com.sap.ip.me.sync.InboundProcessorRegistryImpl.register(InboundProcessorRegistryImpl.java:285)
         at com.sap.ip.me.core.ApplicationManager.registerInboundProcessors(ApplicationManager.java:198)
         at com.sap.ip.me.core.FrameworkInitializer.initializeFramework(FrameworkInitializer.java:379)
         at com.sap.ip.me.core.FrameworkInitializer.main(FrameworkInitializer.java:126)
         at com.sap.ip.me.mdk.api.runtime.Start.startME(Start.java:139)
         at com.sap.ip.me.mdk.api.runtime.Start.main(Start.java:46)
    [20070828 10:58:28:078] E [AppLog/MI/API/Services   ] Problems while saving C:\Program Files\SAP Mobile Infrastructure\sync\inboundProcessors\1.value
    java.io.NotSerializableException: com.sap.ip.me.api.services.MEResourceBundle
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
         at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
         at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
         at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
         at com.sap.ip.me.api.services.IOUtils.serializeObjectToFile(IOUtils.java:875)
         at com.sap.ip.me.api.services.IOUtils.saveHashtableToDirectory(IOUtils.java:801)
         at com.sap.ip.me.sync.InboundProcessorRegistryImpl.register(InboundProcessorRegistryImpl.java:285)
         at com.sap.ip.me.core.ApplicationManager.registerInboundProcessors(ApplicationManager.java:200)
         at com.sap.ip.me.core.FrameworkInitializer.initializeFramework(FrameworkInitializer.java:379)
         at com.sap.ip.me.core.FrameworkInitializer.main(FrameworkInitializer.java:126)
         at com.sap.ip.me.mdk.api.runtime.Start.startME(Start.java:139)
         at com.sap.ip.me.mdk.api.runtime.Start.main(Start.java:46)
    [20070828 10:58:28:140] E [AppLog/MI/API/Services   ] Problems while saving C:\Program Files\SAP Mobile Infrastructure\sync\inboundProcessors\1.value
    java.io.NotSerializableException: com.sap.ip.me.api.services.MEResourceBundle
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
         at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
         at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
         at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
         at com.sap.ip.me.api.services.IOUtils.serializeObjectToFile(IOUtils.java:875)
         at com.sap.ip.me.api.services.IOUtils.saveHashtableToDirectory(IOUtils.java:801)
         at com.sap.ip.me.sync.InboundProcessorRegistryImpl.register(InboundProcessorRegistryImpl.java:285)
         at com.sap.ip.me.core.FrameworkInitializer.initializeFramework(FrameworkInitializer.java:382)
         at com.sap.ip.me.core.FrameworkInitializer.main(FrameworkInitializer.java:126)
         at com.sap.ip.me.mdk.api.runtime.Start.startME(Start.java:139)
         at com.sap.ip.me.mdk.api.runtime.Start.main(Start.java:46)
    [20070828 10:58:36:781] D [MI/API/Sync              ] SyncEventListener com.sap.ip.me.core.StatusUpdater@b1cc87 was registered for key com.sap.ip.me.core.StatusUpdater/MI574f4e32
    [20070828 10:58:36:781] D [MI/Sync                  ] Register inbound processor com.sap.ip.mi.systemnews.InboundListener for method SYSTEMNEWS
    [20070828 10:58:36:812] E [AppLog/MI/API/Services   ] Problems while saving C:\Program Files\SAP Mobile Infrastructure\sync\inboundProcessors\1.value
    java.io.NotSerializableException: com.sap.ip.me.api.services.MEResourceBundle
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
         at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
         at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
         at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
         at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
         at com.sap.ip.me.api.services.IOUtils.serializeObjectToFile(IOUtils.java:875)
         at com.sap.ip.me.api.services.IOUtils.saveHashtableToDirectory(IOUtils.java:801)
         at com.sap.ip.me.sync.InboundProcessorRegistryImpl.register(InboundProcessorRegistryImpl.java:285)
         at com.sap.ip.mi.systemnews.NewsImpl.create(NewsImpl.java:313)
         at com.sap.ip.mi.systemnews.StartListener.userLoggedOn(StartListener.java:24)
         at com.sap.ip.me.core.UserManagerImpl.fireLogon(UserManagerImpl.java:2283)
         at com.sap.ip.me.core.UserManagerImpl.logOnUser(UserManagerImpl.java:766)
         at com.sap.ip.me.core.UserManagerImpl.logOnUser(UserManagerImpl.java:744)
         at com.sap.ip.me.apps.jsp.LoginServlet.doHandleEvent(LoginServlet.java:274)
         at com.sap.ip.me.api.runtime.jsp.AbstractMEHttpServlet.doGetNotThreadSafe(AbstractMEHttpServlet.java:347)
         at com.sap.ip.me.api.runtime.jsp.AbstractMEHttpServlet.doGet(AbstractMEHttpServlet.java:689)
         at com.sap.ip.me.api.runtime.jsp.AbstractMEHttpServlet.doPost(AbstractMEHttpServlet.java:706)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at com.sap.ip.me.api.runtime.jsp.AbstractMEHttpServlet.service(AbstractMEHttpServlet.java:313)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
         at org.apache.tomcat.core.Handler.service(Handler.java:287)
         at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
         at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:806)
         at org.apache.tomcat.core.ContextManager.service(ContextManager.java:752)
         at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
         at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
         at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)

    MI framework tries to serialize all inbound listeners during the registration.
    However,  com.sap.ip.mi.systemnews.InboundListener seems to have a member
    of type com.sap.ip.me.api.services.MEResourceBundle which is not Serializable.
    basically this doesn't do any harm and you can just ignore this. In the previous MI
    SP level, I think we have this observer serialization exception ignored in the code;
    but it seems that implementation been changed...
    regards
    jo

  • File writing serialization

    I have to build a web application using servlet and jsp. The user should edit some
    text file (maybe displaying the file fields in a HTML form).
    I need some suggestions about implementing the synchronization on file writing (since different
    users should try to save the same file simultaneously).
    Do some standard pattern exist about this feature ?
    I suppose to do that using a java bean whith application scope shared by the jsp pages. In this bean
    I will implement all write methods using synchronized.
    Any suggestions ?
    Thanks in advance,
    Mauro.

    well, if you have a single method which does the actual file writing, then you make that method synchronized and you'll have no problems. You can build up the data to write in some object at any time and pass that to that method.
    However, that's still going to present problems when users actually modify the file at the same time. Why does every user have to share 1 file?

  • File Writing with JSP

    Hi all,
    I'm creating a simple app that gets form data and populates it to a file. I want to make sure that each instance (thread?) is able to write to the file and not throw an exception since the file may be currently open by another instance of the jsp. Now I did basic thread programming in C++ a long time ago, so I'm aware of thread waiting conceptually, but I'm not familiar with the java implementation. Can someone show me some basic syntax on how I would go in essentially putting a lock on the file writing portion of the code.
    Thanx much

    I disagree that you should override anything in Threa, especiially the sleep method.
    What you should do is handle the file writing in a producer/consumer fashion. Have a single class that extends Runnable be the consumer. It handles all the file writing issues. You will run this in its own thread.
    Your JSPs (or other threads) fill in a collection, or some other holder, which informs the consumer to write to the file.
    As a brief example, this is a mini logger type of program. I use a class (LogCenter) to log data put in it from other sources (client1 and client2). For the sake of using newer API, I make use of the java.util.concurrent.BlockingQueue (and java.util.concurrent.LinkedBlockingQueue) to make a thread-safe collection and reporting system for text to come in and out of the logger.
    Note, this is far from production. Just something I whipped up when playing with blocking queues a while ago...
    package net.thelukes.steven.thread.test;
    import java.io.PrintWriter;
    import java.util.concurrent.BlockingQueue;
    import java.util.concurrent.LinkedBlockingQueue;
    public class LoggingCenter implements Runnable {
      private PrintWriter output;
      private BlockingQueue<String> toPrint;
      public LoggingCenter() {
        toPrint = new LinkedBlockingQueue<String>(10);
      public void setOutput(PrintWriter pw) {
        if (pw == null)  {
          if (output != null)
            return; //do not replace output with null
          else //pw is null and output is null
            throw new IllegalArgumentException("Ouput PrintWriter must not be NULL");
        else {
          if (output != null) closeOutput(); //if output exists already, close it.
          output = pw;
      public void log(String text) {
        boolean added = false;
        while (!added)
          try {
            toPrint.put(text);
            added=true;
          } catch (InterruptedException ie) {
            ie.printStackTrace();
            try { Thread.sleep(300L); }
            catch (InterruptedException ie2) { ie2.printStackTrace();}
      public void run() {
        try {
          while (true) {
            printLn(toPrint.take());
        } catch (InterruptedException ie) {ie.printStackTrace();}
      private void closeOutput() {
        output.flush();
        output.close();
      private void printLn(String text) {
        if (output == null)
          throw new IllegalStateException
            ("The Output PrintWriter must be set before any output can occur.");
        output.println(text);
        output.flush();
    package net.thelukes.steven.thread.test;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    public class LoggingTest {
      public static void main(String[] args) throws IOException {
        PrintWriter output = new PrintWriter(
          new FileWriter(new File("log.txt")));
        //PrintWriter output = new PrintWriter(System.out, true);
        final LoggingCenter logger = new LoggingCenter();
        logger.setOutput(output);
        Thread t = new Thread(logger);
        t.start();
        Thread client1 = new Thread(
            new Runnable() {
              public void run() {
                while (true) {
                  logger.log("Client 1: "+System.currentTimeMillis());
                  try {
                    Thread.sleep(1250L);
                  } catch (InterruptedException e) {}
        Thread client2 = new Thread(
            new Runnable() {
              public void run() {
                while (true) {
                  logger.log("Client 2: "+System.currentTimeMillis());
                  try {
                    Thread.sleep(2500L);
                  } catch (InterruptedException e) {}
        client1.start();
        client2.start();
    }

  • Executing class files from a Java App dynamically

    Hi!, Is there any way i can execute java .class files from my Java Application dynamically. I know that java uses Dynamic method Invocation. Is that true of class files generated using some other language compiled for the JVM.
    In my case i would like to make a Web browser that interprets HTML and also java applets embeded in them. I would like to use the JRE of the platform execute the applets for me rather than writing the code for my Browser to interpret the class files.
    Thanks in Advance.

    You just need a custom class loader to bring these applets into your JVM.
    http://developer.java.sun.com/developer/onlineTraining/Security/Fundamentals/magercises/URLClassLoader/index.html
    Then you can use the methods of java.lang.Class to create an instance of such a class. As soon as you have it, you can just treat it as a regular Applet and invoke init(), stop() etc. appropriately.
    If you want to execute anything else than conventional Applets, you might consider reflection to find out about methods implemented:
    http://java.sun.com/docs/books/tutorial/reflect/index.html

  • How to read the contents of XML file from my java code

    All,
    I created an rtf report for one of my EBS reports. Now I want to email this report to several people. Using Tim's blog I implemented the email part. I am sending emails to myself based on the USERID logic.
    However I want to email to different people other then me. My email addresses are in the XML file.
    From the java program which sends the email, how can I read the fields from XML file. If any one has done this, Please point me to the right examples.
    Please let me know if there are any exmaples/BLOG's which explain how to do this(basically read the contents of XML file in the Java program).
    Thank You,
    Padma

    Ike,
    Do you have a sample. I am searched so much in this forum for samples. I looked on SAX Parser. I did not find any samples.
    Please help me.
    Thank you for your posting.
    Padma.

  • Help needed  while exporting crystal reports to HTML file format using java

    Help needed  while exporting crystal reports to HTML file format using java api(not using crystalviewer).i want to download the
    html file of the report
    thanks

    the ReportExportFormat class does not have HTML format, it has got to be XML. Export to HTML is available from CR Designer only.
    Edited by: Aasavari Bhave on Jan 24, 2012 11:37 AM

  • How to Install .CAP file in the Java Card?

    Hi Friends..
    How to install *.CAP* file in the Java Card?..
    I've GPShell script as follows :
    mode_211
    enable_trace
    establish_context
    card_connect -readerNumber 2
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f
    install_for_load -pkgAID a00000006203010c01 -nvCodeLimit 500  -sdAID A000000003000000
    load -file HelloWorld.cap
    card_disconnect
    release_contextwith that script i can load HelloWorld.cap file successfully..
    Now, how to install the HelloWorld.cap file?..
    if i add script : load -file HelloWorld.cap i got this error :
    install -file HelloWorld.cap
    file name HelloWorld.cap
    Command --> 80E602001B09A00000006203010C0107A00000015100000006EF04C60201A80000
    Wrapped command --> 84E602002309A00000006203010C0107A00000015100000006EF04C60201
    A80030C859793049B85300
    Response <-- 6985
    install_for_load() returns 0x80206985 (6985: Command not allowed - Conditions of
    use not satisfied.)i ask this question because when i tried to select the applet through its AID, by this script :
    establish_context
    card_connect -readerNumber 2
    select -AID a00000006203010c0101i got this message error : select_application() returns 0x80216A82 (6A82: The application to be selected could not be found.)
    but there's exactly any that AID in my Java Card..
    here's is the list of AID from My Java Card :
    C:\GPShell-1.4.2>GPShell listgp211.txt
    mode_211
    enable_trace
    establish_context
    card_connect -readerNumber 3
    * reader name OMNIKEY CardMan 5x21-CL 0
    select -AID a000000003000000
    Command --> 00A4040008A000000003000000
    Wrapped command --> 00A4040008A000000003000000
    Response <-- 6F108408A000000003000000A5049F6501FF9000
    open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4
    f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
    Command --> 80CA006600
    Wrapped command --> 80CA006600
    Response <-- 664C734A06072A864886FC6B01600C060A2A864886FC6B02020101630906072A864
    886FC6B03640B06092A864886FC6B040215650B06092B8510864864020102660C060A2B060104012
    A026E01029000
    Command --> 8050000008AAF7A87C6013BC0300
    Wrapped command --> 8050000008AAF7A87C6013BC0300
    Response <-- 0000715457173C2A8FC1FF0200937A55C288805D8F2A04CCD43FA7E69000
    Command --> 848201001023CA18742D36165ED992CFF2146C3D51
    Wrapped command --> 848201001023CA18742D36165ED992CFF2146C3D51
    Response <-- 9000
    get_status -element 10
    Command --> 80F21000024F0000
    Wrapped command --> 84F210000A4F004FF8BE1492F7275400
    Response <-- 0CF0544C00004D4F44554C415201000009A00000006203010C010100010AA000000
    06203010C01019000
    GP211_get_status() returned 2 items
    List of Ex. Load File (AID state Ex. Module AIDs)
    f0544c00004d4f44554c4152        1
    a00000006203010c01      1
            a00000006203010c0101
    card_disconnect
    release_contextPlease help me..
    And please correct me if i'm wrong,,
    Thanks in advance..

    Any suggestions for my question?..
    Please help me..
    Thanks in advance..

  • How to call a .jar file from a java bean?

    any body knows how to call a .jar file from a java bean?

    Crosspost!
    http://forum.java.sun.com/thread.jspa?messageID=4349619

Maybe you are looking for

  • Microsoft Forms and Microsoft Visual Basic while opening the Excel file

    Hello, I have issues with 2010 64 bit Office Pro Plus Excel. Whenever I open an Excel file (97-2003 worksheet) which has macros then I get below 2 errors in sequence. Please note that all macro settings are enabled and below are my system configs. Wi

  • SharePoint 2013 - Power View

    Hi, I try to run Power View featrue in SharePoint 2013 but still I get error The feature: "Power View" is not supported in this edition of Reporting Services. I have already installed PowerPivot Add-In and Reporting Service Add-In I see new content t

  • Mapquest doesn't display properly in firefox for windows,why?

    when i go to mapquest, i can't see the address box. When i click on 'maps & directions' it dispalys for about 2 seconds then disappears.

  • Links in received email

    Help – In my received mails any links in the text are coloured blue and underscored. How on earth do I change the colour in my preferences to select a new colour? And also does anyone know if I can remove the underscoring altogether?

  • Creating a PDF drawer

    I have scanned in 10 separate pages, converted them to 10 PDF files and now need to send them out in one attachment. So I need to convert from 10 separate PDF files to 1 PDF file with 10 pages. How?