How to output strings to a file faster.

Hi,
I need to output large among strings to a file. The requirement is that the time of file processing shall be as short as possible. So I implemented as following:
Define a StringBuffer and append all the strings first. Open file. Using BufferedWrite to write into it. Close file.
It works. But sometimes I got OutOfMemoryException if there are to many strings. To avoid this I increased memory.
I wonder if there is any other solution to do it without increasing memory?
Saga

Hi!
As I understand your problem, you have two possible solutions.
1. change your approach to somthing like appanding only a fixed number of strings to a stringbuffer and write it to the file (appending each time your write the buffer), clear the stringbuffer. This will prevent from OutOfMenory exceptions but increase file activity.
2. append the strings directly to the file to prevent OutOfMenory exceptions.This way you have short but frequent file activity.
Hope this helps
Timo

Similar Messages

  • How get output generated as csv file  by reading  by buffered reader and wr

    how get output generated as csv file by reading by buffered reader and writer

    String file_location = "C\temp\csv.txt");
    try {
         URL fileURL = getClass().getResource(file_location);
         if (fileURL != null){
              BufferedReader br = new BufferedReader(new InputStreamReader(fileURL.openStream()));
              String s = br.readLine();
              while (s != null)  {
                   if (!s.equals ("")) {
                        System.out.println(s);
                   s = br.readLine();
              br.close();
         else {
              // error
    catch (IOException ex){ex.printStackTrace();}rykk
    Message was edited by: a dummy
    rykk.

  • How to output data to a file in SCC-SG04?

    I am using SCC-2345 with SCC-SG04 connected to NI-6221 in Windows 2000 in VC6.
    How to output data to a file like data1.dat in VC6 or in Labwindows/CVI?

    Hello mwibm,
    If you just want to do file input/output in LabWindows/CVI, I would take a look at the Formatting and I/O CVI library or the ANSI File I/O functions. For example, if you just want to write an array of data to a file, I would look at the ArrayToFile function or the fwrite/fputs/fprintf ANSI C functions included in stdio.h. The ANSI C functions will also work in Visual Studio. More information on the LabWindows/CVI File I/O functions can be found in CVI help, and more information on ANSI C functions can be found in CVI Help and online at various websites.
    Maybe you could further clarify what problems you are having and what kind of data you want to write to a file.
    Thanks.
    Wendy L
    LabWindows/CVI Developer Newsletter - ni.com/cvinews

  • How to output to an excel file?

    Hi,
    I have written a program that gets data from the database and I like to find out how to output the data to an excel file. I have read about similar topic on the discussion board and the solution are for the online application. Mine is a desktop application. The user can specify what the destination file is. Can anyone help. Thanks.

    The simpliest way is to take your data and write it to a Comma Dilimeted File which Excel can read without any problems or user intervention. You would use an ObjectOutputStream. Hope this helps.

  • How to output results to a file?

    If there is no Debug capability, how to output test results to a file?  Are there any other ways to do this?
    Thanks!

    Dear Sapport,
    You can use the IWDMessageManger to print the message on the webdynpro application iview screen.
    Please refer to the more details for the Webdynpro Logging and Tracing to find the root cause:-
    [Logging in Web Dynpro (Java) - a guide and tutorial for beginners [Part 1]|Logging in Web Dynpro (Java) - a guide and tutorial for beginners [Part 1]]
    [http://wiki.sdn.sap.com/wiki/display/WDJava/LoggingandTracinginWebDynpro|http://wiki.sdn.sap.com/wiki/display/WDJava/LoggingandTracinginWebDynpro]
    Hope it will resolve your issue.
    Best Regards
    Arun Jaiswal
    Edited by: Arun Jaiswal on Mar 5, 2012 12:47 PM

  • How to save string in a file with special-chars

    Hello,
    i´m usingthe MD5-llb to create a password.
    Then i  want to save this MD5-string to a file and later read it back abd compare.
    Works perfect with one proplem:
    Some word create a "\r" in the MD5-string and when i save this string to a file and read it back then its read back as a "\n" so that the compare is not working.
    My question is: How can i save a string exactly like it is to somewhere and read it back (also invisible chars)
    For example the word: heinz
    is in MD5: \r\FB^\07\A6\07T\C7\D9\C2\94\AB\C9\1DS\95 (string indicator as codes display)
    when i save the string to a file then i rerad back: \n\FB^\07\A6\07T\C7\D9\C2\94\AB\C9\1DS\95
    I used the "write text file" and "read text file"
    What do i have to use to save and read the same?
    Thx
    Solved!
    Go to Solution.

    I believe an MD5 hash is 16 bytes long. Use the binary read and write file I/O functions and specify the length of the data to be read or written.
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness

  • How to output strings to an text file and excel file

    Hi guys,
    I am writing a simple application taht process some string inputs from user using a simple GUI. The GUI consists of a series of
    textfields which the user can enter names, age, addresses....etc
    Once they complete filling up that GUI form, they click SUBMIT. All the values will then be read. These strings are then required to be output to 2 files
    1. To a text file which I can open it and read it anytime I wish.
    2. To an excel file which follows a specific format. That is, all names will be written to column B, all ages will be written to column C...etc
    The programme is expected to keep running allow the user to enter details of multiple persons(some 300 sets of data of different persons) until he clicks on End program.
    Please advise how I can output the strings to
    1. Text file
    2. Excel file.
    Many many thanks. I need this for one of my project which is due so so soon...... :((
    Regards
    David

    1. Text file
    See link to "Documentation - Tutorials" on the left
    side of this page.
    2. Excel file
    Dont try to write the real excel format (if you want
    to do it soon).
    - write data to a plain text file.
    - Use tab stops for separation of values.
    - Name file as excel file. (*.xls)
    If you double click this file, excel will import data
    and insert it to a table in the right order by
    itself.
    Excel can save this as real .xls now.
    Anyone here with a better idea? (Try to learn by
    myself)good thing to know for the excel tip :)
    thx

  • How to pass strings when downloading file

    Hi,
    I have a requirement to pass the below mentioned two string at the start of the file when download.
    wf_firstline =  '$$ADD ID=HTAUSRF1 BID=FKI4990016797'.
    wf_secondline = '*03000820000049900167970'.
    pls.provide me pointers how can this be done.
    Thanks.

    if it is a presentation file download,you have to append the data into the table before the data is filled
    and if it is in App.server download,you have to wcan write the strings before transferring the actual data.

  • How to recognize string in txt file and set it as variable

    Hi, 
    I have txt file and somwhere in it string starting with:
    data directory....:
    How (using batch file) find it in the text, read and set the value as a variable? I mean the string is:
    data directory....: c:\datadir
    where what I mean value is  in this case "c:\datadir". So I want batch file to read the txt file, find string starting with "data directory....:" and then set "c:\datadir" as a variable. 
    Best, mac

    It's not very intuitive to do this sort of thing in a batch file. If you have the option to use PowerShell instead, I'd highly recommend it. It's the new way for performing command-line tasks in Windows, and there's no need to struggle with the old command
    prompt anymore.
    Here are PowerShell and batch examples of doing this type of string parsing:
    # PowerShell:
    $dataDirectory = Get-Content .\test.txt |
    ForEach-Object {
    if ($_ -match '^\s*data directory\.*:\s*(.+?)\s*$')
    $matches[1]
    break
    $dataDirectory
    # Batch file:
    @echo off
    setlocal EnableDelayedExpansion
    set DATA_DIRECTORY=
    for /F "tokens=1,* delims=:" %%a in (test.txt) do (
    set PROPERTY=%%a
    set PROPERTY=!PROPERTY:~0,14!
    if /I "!PROPERTY!" equ "data directory" (
    set DATA_DIRECTORY=%%b
    :RemovingSpaces
    if "%DATA_DIRECTORY:~0,1%" neq " " goto :SpacesRemoved
    set DATA_DIRECTORY=%DATA_DIRECTORY:~1%
    goto :RemovingSpaces
    :SpacesRemoved
    echo %DATA_DIRECTORY%
    endlocal

  • How to output strings on an LCD

    I have a project and I want to use labview to display some strings as output on an LCD. Can anyone tell me how to use an LCD? or how to enter data to it and how we connect it?
    Thank you

    Abook7 wrote:
    So I understand from what you're saying that using an LCD would take a lot of time to configure and build a special circuit for  it  and to connect it to labview?
    Not with a serial LCD.  You may find one that is 232 compatible.  This would only require you send the appropriate commands and strings to the device.  If you go the parallel route, more work would be involved.
    Reese, (former CLAD, future CLD)
    Some people call me the Space Cowboy!
    Some call me the gangster of love.
    Some people call me MoReese!
    ...I'm right here baby, right here, right here, right here at home

  • How  to output a CLOB to file using UTF-8

    I am working on an 9.2.04 database. I'm generating xml using SQLX functions and inserting the result into a table with a column of XMLTYPE datatype.
    The database characterset is WE8ISO8859P15. I need to write the contents of my XMLTYPE column to a file on the server using UTF-8 encoding. I've tried The following :
    declare
    temp_xml xmltype;
    cl clob;
    begin
    select myxml into temp_xml from xml_table;
    cl := temp_xml.getClobVal;
    clob_to_xmlfile('XMLDIR','myfilename.xml',cl);
    end;
    The code for clob_to_xmlfile is :
    PROCEDURE clob_to_xmlfile( p_dir IN VARCHAR2,
    p_file IN VARCHAR2,
    p_clob IN CLOB )
    AS
    l_output utl_file.file_type;
    l_amt number default 32000;
    l_offset number default 1;
    l_length number default nvl(dbms_lob.getlength(p_clob),0);
    BEGIN
    -- notice use of fopen_nchar and put_nchar to use unicode
    l_output := utl_file.fopen_nchar(p_dir, p_file, 'w', 32760);
    while ( l_offset < l_length )
    loop
    utl_file.put_nchar(l_output,
    dbms_lob.substr(p_clob,l_amt,l_offset) );
    utl_file.fflush(l_output);
    l_offset := l_offset + l_amt;
    end loop;
    utl_file.new_line(l_output);
    utl_file.fclose(l_output);
    END clob_to_xmlfile;
    However, the resultant file has somehow 'lost' characters, thereby making the xml malformed. I know by inspection that the XMLTYPE column in my table contains valid xml, so the 'corruption' is occuring when I try writing it to file.
    Is this something to do with characterset s ?? Can anyone help me with this ??

    In 10g, DBMS_XMLDOM has writeToFile() writing XML into files without the temporary lobs. It lets you specify a character set parameter. However, 9.2.0.4 doesn't not support character set conversion so this may not work. The options would be upgrading to 10g or building the function like what you have.
    The presented code seems to have the followings issues:
    (1) the length expansion is not taken into accout; utf-8 encoding needs equal or grater number of bytes to represent the same string in iso-8859-15,
    potentially up to 3x. If your buffer was 32k, you should not read more than 10k at a time in order to make sure all characters read from CLOB can fit into the buffer. This problem apparently can cause unexpected behavior: a
    symptom may be lost characters.
    (2) while ( offset < length ) has a off-by-one problem, as we start counting LOB offset with 1, not zero.
    (3) I think utl_file.fflush needs the new line character at the end of buffer so it can tell how much to write. It would be difficult to write a bufferful of data because you have no idea where a line begins and ends
    while reading a CLOB.
    Probably a more practical approach to make this work would be using the PUT_RAW function with autoflush turned on, where data can be written blindly regardless of when the buffer should be flushed. That is:
    -read 10k from the clob (DBMS_LOB.READ)
    -manually convert it into UTF-8 to a 30k buffer (UTL_RAW.CONVERT)
    -then write it with UTL_FILE.PUT_RAW (UTL_RAW.CAST_TO_RAW)

  • How to output to client the file ?

    Hello respected developers. I want to send to client the wmsword file, if the client press on url. What link i've to write and what procedure in oracle must be created? Siply --- !!how to do this!! ? File forexample /export/home/alex/1.doc? I don't hope for request, but.......

    Hi Pavel,
    If you do not have a strict requirement of having the files you want to access from a fixed location then you can put the file in a webserver and access is with a URL for eg:
    Put the file under $IAS_HOME/j2ee/home/default-web-app directory and access it from the bowser like
    http://host:port/youfile
    You can add this Link to the required portal component,
    and the user can access it by clicking on this Link
    Hope this helps
    Thanks
    Vineet

  • How to open a large file faster?

    Hi,
    I am developing a website which will host some documents. Size of the docuemnts are between 1MB to 10MB ans they are PDF documents. I open the document in a new page based on some inout parameters.
    I am using the following code. But it takes long time to get displayed. Is there any other way of reading and displaying the file faster? Is it possible to use buffer reader here and make it faster? Please help.
    OpenFileStream display =new OpenFileStream();
    String fileName =request.getParameter("fileName");
    display.displayFile(request,response,fileName);

    The code which I sent is working. I do not know why you said it can not work.you call these methods
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html#read(byte[])
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html#available()
    in this code int numOfBytes = fileInput.available();
    byte byteArray[] = new byte[numOfBytes];
    int totalBytes = reader.read(byteArray);In general its not guaranteed that fileInput.available() will return the number of bytes in the file. It returns how many bytes it can read before blocking. It says: "Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream"
    try adding byte byteArray[] = new byte[numOfBytes];
    if(numOfBytes!=new File(fileName).length()) {
       System.out.println(fileName+" has not been read correctly");
    }to your code to see if this is happening.
    Now I tried using the following code. Will it be
    faster than previous code? I don't see why it would be - have you tried running it and timing it?
    I still think the only (possibly very small) performance benefit you can get here is to overlap the reading and writing phases - so that you start reading the file, and writing it to the output stream at the same time.

  • Problem in outputting a string into a file

    Hi guys,
    I tried to output a string to a file. The string is 'Size : 30u201D X 13 ½u201D X17 ¾u201D(H)'.
    However, with this code :
    l_file = '/erp/reports/testgk.txt'.
    l_str = 'Size : 30u201D X 13 ½u201D X17 ¾u201D(H)'.
    OPEN DATASET l_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    TRANSFER l_str TO l_file.
    It returned me a weird string: 'Size : 30M-bM-@M-] X 13 M-BM-=M-bM-@M-] X17 M-BM->M-bM-@M-](H)'
    Would you please let me know how to solve this problem?
    Thanks, gk

    Hello gk,
    I tried this code & works fine for me though:
    DATA: v_data TYPE string VALUE ' 30u201D X 13 ½u201D X17 ¾u201D(H)',
          v_file TYPE string VALUE
                  '\glbwi720InterfaceID2100I_MB_207INsdn.txt'.
    OPEN DATASET v_file FOR OUTPUT
    IN TEXT MODE
    ENCODING DEFAULT.
    IF sy-subrc = 0.
      TRANSFER v_data TO v_file.
      CLOSE DATASET v_file.
    ENDIF.
    Looks like the "usual" ENCODING problem
    BR,
    Suhas

  • How do I create individual xml files from the parsed data output of a xml file?

    I have written a program (DOM Parser) that parses data from a XMl File. I would like to create an individual file with the corresponding name for each set of data parsed from the xml document. If the parsed output is Single, Double, Triple, I would like to create an individual xml file (Single.xml, Double.xml, Triple.xml)with those corresponding names. How do I create the xml files and give each file the name of my parsed data output? Thanks in advance for your help.
    import java.io.IOException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class MyDomParser {
      public static void main(String[] args) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse("ENtemplate.xml");
      doc.normalize();
      NodeList rootNodes = doc.getElementsByTagName("templates");
      Node rootNode = rootNodes.item(0);
      Element rootElement = (Element) rootNode;
      NodeList templateList = rootElement.getElementsByTagName("template");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      System.out.println("Template" + ": " +templateElement.getAttribute("name")+ ".xml");
      } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

    Ive posted the new code but now I'm getting a FileAlreadyExistException error. How do I handle this exception error correctly in my code?
    import java.io.IOException;
    import java.nio.file.FileAlreadyExistsException;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class MyDomParser {
      public static void main(String[] args) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse("ENtemplate.xml");
      doc.normalize();
      NodeList rootNodes = doc.getElementsByTagName("templates");
      Node rootNode = rootNodes.item(0);
      Element rootElement = (Element) rootNode;
      NodeList templateList = rootElement.getElementsByTagName("template");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      System.out.println(templateElement.getAttribute("name")+ ".xml");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      String fileName = templateElement.getAttribute("name") + ".xml";
      Files.createFile(Paths.get(fileName));
      System.out.println("File" + ":" + fileName + ".xml created");
      } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

Maybe you are looking for

  • Broadband drops out after bt upgrade work in area

    Hope someone can help because the call centre is helpful but unfortunetly the help they give me is what I have tried before. On Wednesday 17th August I received an ewmail from the BT Migration team stating that upgrade work would be taking place at m

  • Compatibility of epson scanner w/ intel imac

    I have 2 new intel imacs, as well as a G4 imac. I'm trying to connect my new Epson scanner (Perfection 4990 Photo). When installing the software, it is looking for a classic environment. The online drivers from Epson's website seem to be for v10.4.4,

  • Windows Server 2012 Pooled Virtual Desktop collection GetVMstate issue

    I am trying to create a Pooled Desktop collection with my Powered off VM and it errors out The virtual desktop must be in a stopped state:  Could not identify the state of the virtual desktop.  Ensure that the RD virtualisation host server is availab

  • DB Adapter for Logical Delete - selecting multiple StatusesAND

    Hi, I am using SOA 11.1.1.3 and my requirement is to use a DB Adapter to poll both ERROR & NEW Records. Once Polled, I want the status to be changed to "PICKED" (Logical Delete) The DB Adapter only allows for a single Unread Value to be selected. I t

  • TOSHIBA NB550D-111 Recovery problem due to swm error

    I own a NB550D-111 (preinstalled W7 Starter SP1 32 bit, av Security Essentials), used mainly for browsing, chat and Skype. Following the july updates, the OS began greeting me with blue screen at every start. I choosed "Startup repair", and after som