Storing data in files in java

Hi all,
If my application can not establish connection with the server it is storing 8000 xml files(one file per record).After connection with the server resumes it sends these xml files to server one by one and simultaneously deletes these files.
I want to know ,wheather it is a good design or not.My requirement is to store
8000 records at the local machine when server is down and then send these records one by one when server comes up.Please reply if anybody has something
in this respect.
With regards,
Ajse

Isn't it possible to store all 8000 records in one file?

Similar Messages

  • STORING DATA IN FILE IN XML FORMAT THROUGH JAVA ?

    HOW TO STORE DATA IN FILE IN XML FORMAT THROUGH JAVA PROGRAM?

    Have you looked into JAXB?
    That is a new way of processing XML into Java classes or visa versa.
    Otherwise, there are a lot of other XML related tools for Java in the -XML link on the left side of the page.

  • How to store a data on txt file through java program

    that means i want a coding for write data on txt file using java program.that storing data is stored like this formate,
    sathees
    krishnan
    rama
    suresh
    Stored on one by one. not like this
    sathees krishnan rama suresh.........

    import java.io.*;
    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    public class rsk1{
    public static void main (String argv []){
    try {
    String sr[] = new String[100];
                   String s1=" ";
                   int j=0;
                   DataInputStream in = new DataInputStream(System.in);
                   OutputStream f1 = new FileOutputStream("file1.txt");
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document doc = docBuilder.parse (new File("book.xml"));
    // normalize text representation
    doc.getDocumentElement ().normalize ();
    System.out.println ("Root element of the doc is " +
    doc.getDocumentElement().getNodeName());
    NodeList listOfPersons = doc.getElementsByTagName("person");
    int totalPersons = listOfPersons.getLength();
    System.out.println("Total no of people : " + totalPersons);
    for(int s=0; s<listOfPersons.getLength() ; s++){
    Node firstPersonNode = listOfPersons.item(s);
    if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){
    Element firstPersonElement = (Element)firstPersonNode;
    NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
    Element firstNameElement = (Element)firstNameList.item(0);
    NodeList textFNList = firstNameElement.getChildNodes();
    sr[++j]=((Node)textFNList.item(0)).getNodeValue().trim();
    NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
    Element lastNameElement = (Element)lastNameList.item(0);
    NodeList textLNList = lastNameElement.getChildNodes();
    sr[++j]=((Node)textLNList.item(0)).getNodeValue().trim();
    NodeList ageList = firstPersonElement.getElementsByTagName("age");
    Element ageElement = (Element)ageList.item(0);
    NodeList textAgeList = ageElement.getChildNodes();
    sr[++j]=((Node)textAgeList.item(0)).getNodeValue().trim();
    NodeList stuList = firstPersonElement.getElementsByTagName("stu");
    Element stuElement = (Element)stuList.item(0);
    NodeList textstuList = stuElement.getChildNodes();
    sr[++j]=((Node)textstuList.item(0)).getNodeValue().trim();
    }//end of if clause
    }//end of for loop with s var
    System.out.println("Process completed");
    for(int i=1;i<=j;i++)
                   byte buf[] = sr.getBytes();
                                       byte buf1[] = s1.getBytes();
         f1.write(buf);
                                       f1.write(buf1);
    f1.close();
    }catch (SAXParseException err) {
    System.out.println ("** Parsing error" + ", line "
    + err.getLineNumber () + ", uri " + err.getSystemId ());
    System.out.println(" " + err.getMessage ());
    }catch (SAXException e) {
    Exception x = e.getException ();
    ((x == null) ? e : x).printStackTrace ();
    }catch (Throwable t) {
    t.printStackTrace ();
    }//end of main

  • Executing batch file from Java stored procedure hang

    Dears,
    I'm using the following code to execute batch file from Java Stored procedure, which is working fine from Java IDE JDeveloper 10.1.3.4.
    public static String runFile(String drive)
    String result = "";
    String content = "echo off\n" + "vol " + drive + ": | find /i \"Serial Number is\"";
    try {
    File directory = new File(drive + ":");
    File file = File.createTempFile("bb1", ".bat", directory);
    file.deleteOnExit();
    FileWriter fw = new java.io.FileWriter(file);
    fw.write(content);
    fw.close();
    // The next line is the command causing the problem
    Process p = Runtime.getRuntime().exec("cmd.exe /c " + file.getPath());
    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line = input.readLine()) != null)
    result += line;
    input.close();
    file.delete();
    result = result.substring( result.lastIndexOf( ' ' )).trim();
    } catch (Exception e) {
    e.printStackTrace();
    result = e.getClass().getName() + " : " + e.getMessage();
    return result;
    The above code is used in getting the volume of a drive on windows, something like "80EC-C230"
    I gave the SYSTEM schema the required privilege to execute the code.
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'java.io.FilePermission', '&lt;&lt;ALL FILES&gt;&gt;', 'read ,write, execute, delete');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    GRANT JAVAUSERPRIV TO SYSTEM;
    I have used the following to load the class in Oracle 9ir2 DB:
    loadjava -u [system/******@orcl|mailto:system/******@orcl] -v -resolve C:\Server\src\net\dev\Util.java
    CREATE FUNCTION A1(drive IN VARCHAR2) RETURN VARCHAR2 AS LANGUAGE JAVA NAME 'net.dev.Util.a1(java.lang.String) return java.lang.String';
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    The problem that it hangs when I execute the call to the function (I have indicated the line causing the problem in a comment in the code).
    I have seen similar problems on other forums, but no solution posted
    [http://oracle.ittoolbox.com/groups/technical-functional/oracle-jdeveloper-l/run-an-exe-file-using-oracle-database-trigger-1567662]
    I have posted this in JDeveloper forum ([t-853821]) but suggested to post for forum in DB.
    Can anyne help?

    Dear Peter,
    You are totally right, I got this as mistake copy paste. I'm just having a Java utility for running external files outside Oracle DB, this is the method runFile()
    I'm passing it the content of script and names of file to be created on the fly and executed then deleted, sorry for the mistake in creating caller function.
    The main point, how I claim that the line in code where creating external process is the problem. I have tried the code with commenting this line and it was working ok, I made this to make sure of the permission required that I need to give to the schema passing security permission problems.
    The function script is running perfect if I'm executing vbs script outside Oracle using something like "cscript //NoLogo aaa1.vbs", but when I use the command line the call just never returns to me "cmd.exe /c bb1.bat".
    where content of bb1.bat as follows:
    echo off
    vol C: | find /i "Serial Number is"
    The above batch file just get the serial number of hard drive assigned when windows formatted HD.
    Same code runs outside Oracle just fine, but inside Oracle doesn't return if I exectued the following:
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    Never returns
    Thanks for tracing teh issue to that details ;) hope you coul help.

  • How to read the data from Excel file and Store in XML file using java

    Hi All,
    I got a problem with Excel file.
    My problem is how to read the data from Excel file and Store in XML file using java excel api.
    For getting the data from Excel file what are all the steps i need to follow to get the correct result.
    Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
    Thanks & Regards,
    Sreenu,
    [email protected],
    india,

    If you want someone to do your work, please have the courtesy to provide payment.
    http://www.rentacoder.com

  • Read multiple files and write data on a single  file in java

    Hello,
    I am facing difficulty that I want to read multiple files in java and write their data to a single file. Means Write data in one file from multiple files in java
    Please help me out.
    Naveed.

    algorithm should be something like:
    File uniqueFile = new File();
    for (File f : manyFilesToRead)
       while (readingF)
           write(dataFromF, intoUniqueFile);

  • Why files in Lightroom mobile and files in the creative cloud not the same? idea-  one place(stored date) for all application ??????

    Why files in Lightroom mobile and files in the creative cloud not the same? idea- one place(stored date) for all application ??????

    Lightroom Mobile is not a cloud storage service. You shouldn't treat it as a way of backing up your files. You are merely storing Smart Previews of your files in the cloud space, high-quality JPEGs of your files regardless of their original format on your desktop. The point is that they are there so you can continue editing them in a Lightroom-like environment even while away from your desktop/laptop computer. The files in Lightroom Mobile can only be used in Lightroom Mobile.
    This is very different from what is offered by the Creative Cloud storage, which can be used to synchronize your files between any device (that can support the individual files).
    The vast difference in how each service works and its intended use is why they are separate.

  • How to edit the existing data in the XML file from java programming.

    Hi all
    i am able to create XML file with the sample data as below from java programming.
    i need sample code on how to edit the existing data in the XML file?
    for example
    <?xml version="1.0"?>
       <mydata>
               <data1>
                         <key1>467</key1>
                        <name1>Paul</name1>
                        <id1>123</id1>
              </data1>
              <data2>
                         <key2>467</key2>
                        <name2>Paul</name2>
                        <id2>123</id2>
              </data2>
        </mydata>
    i am able to insert the data in the XML.
    now i need sample code on how to modify the data in the above XML file from the java programming for only key2,name2,id2 tags only. the remaining tags data in the XML file i want to keep same data except for key2,name2,id2 which are i want to modify from java code
    Regards
    Sunil
    [points will be always rewardable]

    hi
    u need a parser or validate the xml file for to read the xml file from java coding u need for this
    xml4j.jar u can download this file  from here
    http://www.alphaworks.ibm.com/tech/xml4j
    or we can use the SAX(simple API for XML)
    some sample applications for this
    http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html
    http://www.developertutorials.com/tutorials/java/read-xml-file-in-java-050611/page1.html
    http://www.xml-training-guide.com/e-xml44.html
    let me know u need any other info
    bvr

  • How to accessed,created and modified date of particular file in java

    Hi,
    I am facing one problem.
    I know how to get the modified date/time of file in java.
    but i don't know how to find created and accessed date/time of file in java.
    Thanks,
    Tejas

    I guess thats not possible in in Windows.
    But if u r trying it on a unix machine.
    You can use Runtime class to call exec on the command
    ls -l filename
    and then store the result in a file . And then take out the last modified time. But you cant get created time.
    Thats a clumpsy way i believe.

  • Storing the last modified date for files in a HashMap

    This method gets a list of all the .java files in the source subdirectory, gets the last modified date for them and stores the file name and last modified date in a HashMap.
    import java.util.HashMap;
    import java.io.FilenameFilter;
    import java.io.File;
    import java.util.ArrayList;
    public class myClass
         public static void main(String[] args)
              HashMap result = getLastModified();
         static FilenameFilter javaFilter = new FilenameFilter()
            public boolean accept(File dir, String name)
                return name.endsWith(".java");
         public HashMap getLastModified()
              HashMap lastModified = new HashMap();
              ArrayList javaFiles = new ArrayList();
              File sourceDir = new File(".\\Source");
              File currentFile;
              long lLastModified;
              //get a list of all the .java files in the source directory
              javaFiles=listFiles(javaFilter);
              //for all .java files get and store the last modified date
              for(int i=0; i<javaFiles.size(); i++)
                   currentFile=(File)javaFiles.get(i);
                   lLastModified=currentFile.lastModified();
                   lastModified.put(currentFile, lLastModified);
              return lastModified;
    }The problems I am getting are:
    >
    The method listFiles(FilenameFilter) is undefined for the type myClass
    and
    >
    The method put(Object, Object) in the type HashMap is not applicable for the arguments (File, long)
    can anyone help? What's the best way to go aobut this?

    Thanks for the replies abenstex I modified it so that javaFiles is now a File[] and made the change you suggested but I still have the second problem, here's the code so far:
    import java.util.HashMap;
    import java.io.FilenameFilter;
    import java.io.File;
    import java.util.ArrayList;
    public class myClass
         public static void main(String[] args)
              HashMap result = getLastModified();
         static FilenameFilter javaFilter = new FilenameFilter()
            public boolean accept(File dir, String name)
                return name.endsWith(".java");
         public HashMap getLastModified()
              HashMap lastModified = new HashMap();
              File[] javaFiles = {};
              File sourceDir = new File(".\\Source");
              File currentFile;
              long lLastModified;
              //get a list of all the .java files in the source directory
              javaFiles=sourceDir.listFiles(javaFilter);
              //for all .java files get and store the last modified date
              for(int i=0; i<javaFiles.length; i++)
                   currentFile=(File)javaFiles;
                   lLastModified=currentFile.lastModified();
                   lastModified.put(currentFile, lLastModified);
              return lastModified;

  • Update file date/time stamp using java

    Let me explain you what I am going through:-
    I have created a java based installer using Jexpress tool and after I do the installation of my files, the files takes the current date rather then taking the date when it was created or modified.
    Everything goes into JAR and I heard that Jar file do not retain the date/time stamp of the file.
    I would like to know if we can change the date and time stamp of the files using Java.
    Is there any method to do that or can we do this by writing the java class?
    Thank You
    Mehul

    Did you check it?
    I did.
    $ jar cvf ~/ui *.m3u
    added manifest
    adding: Amollhgv.m3u(in = 42) (out= 24)(deflated 42%)
    adding: Brand1.m3u(in = 56) (out= 27)(deflated 51%)
    adding: Brand2.m3u(in = 42) (out= 24)(deflated 42%)
    adding: Brand3.m3u(in = 42) (out= 24)(deflated 42%)
    adding: Brand4.m3u(in = 42) (out= 24)(deflated 42%)
    adding: Brand5.m3u(in = 42) (out= 24)(deflated 42%)
    adding: Brand6.m3u(in = 42) (out= 24)(deflated 42%)
    adding: Edurhgv.m3u(in = 42) (out= 24)(deflated 42%)
    $ unzip -l ~/ui
    Archive:  /home/ijbalazs/ui
      Length     Date   Time    Name
            0  12-04-03 17:53   META-INF/
           71  12-04-03 17:53   META-INF/MANIFEST.MF
           42  08-26-02 01:03   Amollhgv.m3u
           56  11-22-98 01:15   Brand1.m3u
           42  08-26-02 01:04   Brand2.m3u
           42  08-26-02 01:04   Brand3.m3u
           42  08-26-02 01:04   Brand4.m3u
           42  08-26-02 01:04   Brand5.m3u
           42  08-26-02 01:04   Brand6.m3u
           42  08-26-02 01:04   Edurhgv.m3u
          421                   10 files

  • How to Write data in Excel File using java

    Hi
    can anybody help me to write data in excel file
    using java code
    Thankx In Advance

    How much are you willing to pay for that?
    If you want it for free, http://jexcelapi.sourceforge.net/

  • XML data file links java and sap

    Hi ,
    Please help me this
    How to connect xml file to java into sap
    please send me sample scenario.
    in java i call the this sap function module  'BAPI_MAT_BOM_EXISTENCE_CHECK'.
    1. Check BOM existence with BAPI_MAT_BOM_EXISTENCE_CHECK
    2. Exit BOM diff if BOM doesn’t exist
    3. Read BOM structure with CSAP_MAT_BOM_READ
    4. Compare SAP BOM items incl. subitems to XML BOM items and subitems

    currently I use following methods tu opload and to transfor the xml into a string.
    * Method to create XML from data file
      CALL METHOD instance->import_from_file
        EXPORTING
          filename = gf_filename
        RECEIVING
          retcode  = ch_retcode.
    * Convert into XML-Stream
      CALL METHOD instance->render_2_string
    *  EXPORTING
    *    pretty_print = 'X'
        IMPORTING
        retcode      = ch_retcode
          stream       = lf_string .
    *    size         = .
    When I use read dataset the output of the xml is into an internal table where I have many lines depending on the XML data file, this means if my xml has 10lines the internal table of read dataset has also 10 lines but I need a string to make the transformation of the xml.

  • How to write data to file Java ME cldc 1.1 midp 2.0?

    I newly in java me, please help me.
    I make project in NetBeans 7.0.1. and use cldc 1.1 midp 2.0.
    I want to write data to the file.
    How can I do it?
    I try to use FileOutputStream. But it don't exists in java.io
    NetBeans shows me only this list of classes and interfaces in java.io:
    ByteArrayInputStream, ByteArrayOutputStream, DataInput, DataInputStream, DataOutput, DataOutputStream, InputStream, InputStreamReader, OutputStream, OutputStreamWriter, PrintStream, Reader, Writer.
    Why it so short?
    And how I can write data to file?
    Data can be array of bytes (byte[]) or Object it better.

    You must use JSR 75: FileConnection. Please check the following article "Getting Started with the FileConnection APIs":
    http://developers.sun.com/mobility/apis/articles/fileconnection/
    Be sure to use FileSystemRegistry.listRoots().
    And welcome to Java ME development. :)

  • How to store xml data into file in xml format through java program?

    HI Friends,
    Please let me know
    How to store xml data into file in xml format through java program?
    thanks......
    can discuss further at messenger.....
    Avanish Kumar Singh
    Software Engineer,
    Samsung India Development Center,
    Bangalore--560001.
    [email protected]

    Hi i need to write the data from an XML file to a Microsoft SQL SErver database!
    i got a piece of code from the net which allows me to parse th file:
    import java.io.IOException;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    import org.apache.xerces.parsers.SAXParser;
    import java.lang.*;
    public class MySaxParser extends DefaultHandler
    private static int INDENT = 4;
    private static String attList = "";
    public static void main(String[] argv)
    if (argv.length != 1)
    System.out.println("Usage: java MySaxParser [URI]");
    System.exit(0);
    String uri = argv[0];
    try
    XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    MySaxParser MySaxParserInstance = new MySaxParser();
    parser.setContentHandler(MySaxParserInstance);
    parser.parse(uri);
    catch(IOException ioe)
    ioe.printStackTrace();
    catch(SAXException saxe)
    saxe.printStackTrace();
    private int idx = 0;
    public void characters(char[] ch, int start, int length)
    throws SAXException
    String s = new String(ch, start, length);
    if (ch[0] == '\n')
    return;
    System.out.println(getIndent() + " Value: " + s);
    public void endDocument() throws SAXException
    idx -= INDENT;
    public void endElement(String uri, String localName, String qName) throws SAXException
    if (!attList.equals(""))
    System.out.println(getIndent() + " Attributes: " + attList);
    attList = "";
    System.out.println(getIndent() + "end document");
    idx -= INDENT;
    public void startDocument() throws SAXException
    idx += INDENT;
    public void startElement(String uri,
    String localName,
    String qName,
    Attributes attributes) throws SAXException
    idx += INDENT;
    System.out.println('\n' + getIndent() + "start element: " + localName);
    if (localName.compareTo("Machine") == 0)
    System.out.println("YES");
    if (attributes.getLength() > 0)
    idx += INDENT;
    for (int i = 0; i < attributes.getLength(); i++)
    attList = attList + attributes.getLocalName(i) + " = " + attributes.getValue(i);
    if (i < (attributes.getLength() - 1))
    attList = attList + ", ";
    idx-= INDENT;
    private String getIndent()
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < idx; i++)
    sb.append(" ");
    return sb.toString();
    }// END PRGM
    Now , am not a very good Java DEv. and i need to find a soln. to this prob within 1 week.
    The next step is to write the data to the DB.
    Am sending an example of my file:
    <Start>
    <Machine>
    <Hostname> IPCServer </Hostname>
    <HostID> 80c04499 </HostID>
    <MachineType> sun4u [ID 466748 kern.info] Sun Ultra 5/10 UPA/PCI (UltraSPARC-IIi 360MHz) </MachineType>
    <CPU> UltraSPARC-IIi at 360 MHz </CPU>
    <Memory> RAM : 512 MB </Memory>
    <HostAdapter>
    <HA> kern.info] </HA>
    </HostAdapter>
    <Harddisks>
    <HD>
    <HD1> c0t0d0 ctrl kern.info] target 0 lun 0 </HD1>
    <HD2> ST38420A 8.2 GB </HD2>
    </HD>
    </Harddisks>
    <GraphicCard> m64B : PCI PGX 8-bit +Accel. </GraphicCard>
    <NetworkType> hme0 : Fast-Ethernet </NetworkType>
    <EthernetAddress> 09:00:30:C1:34:90 </EthernetAddress>
    <IPAddress> 149.51.23.140 </IPAddress>
    </Machine>
    </Start>
    Note that i can have more than 1 machines (meaning that i have to loop thru the file to be able to write to the DB)
    Cal u tellme what to do!
    Even better- do u have a piece of code that will help me understand and implement the database writing portion?
    I badly need help here.
    THANX

Maybe you are looking for

  • Error while Importing SYSTEM objects into 9.2.0.6

    HI, I got the following error while importing data into 9.2.0.6 DB . It is related to a SYSTEM object. . importing SYSTEM's objects into SYSTEM IMP-00017: following statement failed with ORACLE error 2270: "ALTER TABLE "DEF$_CALLDEST" ADD CONSTRAINT

  • AP Down Payment Invoice Service

    Dear all, When I made an AP Down Payment Invoice Service, I want to choose Down Payment Clearing account from GL Account (row level), but when I browse the GL Account, there's no account appear. Anybody knows ? This is different with AP Down Payment

  • 10.10.3 overloads CPU, overheats, freezes, reboots every 3 minutes

    The problem appears to be with the new Photos app. When I run it and look at the CPU usage, it's pegging at 200-250% usage.... shortly thereafter followed by the fan coming on, then the whole thing overheating, freezing, and hard rebooting. I think I

  • Available Now: Oracle Database Lite 10g Release 1

    The Oracle Database Lite development team is pleased to announce the availability of Oracle Database Lite 10g (10.0.0.0.0) for Windows 2000/XP, Solaris 2.6, 2.7, 2.8, and Red Hat Enterprise Linux AS/ES 2.1/3.0 platforms. The Windows release is curren

  • Getting error when installing addons on production

    Hi all, I have created addons setups using "sapb1addon installer.NET wizard"  when i intalled its, on development server its working fine same thing when i am trying to install on production server i am getting below error msg plz solve it as soon as