Reading entire txt file into memory?

When you are using BufferedReader to read info into a buffer, that means you are reading the file into memory, correct? (Is that what buffer means?)
I want to look for pattern matches in text files (about 1000 of them) using the regex utils. But I don't want to read and examine the text files line by line. I want to read in the entire text file into memory first and then look for the pattern matches. The text files generally don't exceed about 15K in size. I'm only going one file at a time, too, so this won't give me any out of memory errors, will it?
And more importantly, how do I do it? I mean the "reading in the file" part only. I have my RegEx, I have my array of files to examine already. I just can't figure out the right code to use to read each file into memory before I look for pattern matches.
Could someone help, please?

When you are using BufferedReader to read info into a
buffer, that means you are reading the file into
memory, correct? (Is that what buffer means?)Yes.
I want to look for pattern matches in text files
(about 1000 of them) using the regex utils. But I
don't want to read and examine the text files line by
line.Why not?
I want to read in the entire text file into
memory first and then look for the pattern matches.Why?
The text files generally don't exceed about 15K in
size. I'm only going one file at a time, too, so
this won't give me any out of memory errors, will
it?Depends on how much memory you've given the VM and how much of that it's using already at the time you read the files, but in general, probably not a problem.
And more importantly, how do I do it? I mean the
"reading in the file" part only.Use BufferedReader to read line by line and then append each line (plus a newline, since BR.readLine() strips those off) to a StringBuilder.
Or use a BufferedInputStream and and array that's as big as the file, and in a loop, try to read as much as is left into that array at an offset equal to how much has been read so far.
I still think this is probably not a good approach though.

Similar Messages

  • Cannot Read Entire TXT Files in "Notes" folder

    Ihave a 4G iPod nano (red, if relevant... I think it's a 4g?) I cannot read entire text files in the notes folder. I can read part of the file, usually up to about a 2 KB size in standard Unicode format, but I am unable to view the entire text file. For example, I have a copy of Beowulf on my iPod that is about 267KB in size; however, I can only read through 1.87KB of it. The rest shows up in Windows Explorer and is fully functional there, but I Cannot view it from my iPod.
    Anyone else have this problem, and know what I can do to fix this (besides breaking it up into about 50 chapters?)
    Thanks Much!
    intel.ectual
    programmer, code-guru, and graphic designer
    Compaq Presario Athlon 1.7GHz 64-bit 1GB RAM and a very comepetent user   Windows XP Pro  
    Compaq Presario Athlon 1.7GHz 64-bit 1GB RAM and a very comepetent user   Windows XP Pro  

    The max size for any note that can be read in the notes on ipod is 4kb. That said there is no alternative way of getting around this size. here is a good article about working with ipod notes.
    http://www.macworld.com/2004/09/secrets/septgeekfactor/index.php
    and on another note from another of your posts.
    jsut to make you aware of not doing something stupid adn cursing about it.
    DO NOT TRY AND USE IPODLINUX ON YOUR IPOD NANO.
    unless you really want to VOID your warranty and also fry your nano to become a expensive PAPERWEIGHT!!
    many have stupidly done this and have come here cursing as to why their ipod nano is fried adn not working at all! Just be smart and make note that that hack software doenst even work for the 2g ipod nano!
    GFF:)

  • Help! How to read a .txt file into a Java class and make 2D array?

    Hi guys,
    Im a newbie with arrays, just started really using them.. please bear with me if I don't seem to understand much..
    I have a .txt file that contains either a square or rectangle (random width and length).. How can I read each line into a Java class into a 2D array with rows and columns?

    Example :
    import javax.swing.*;
    import java.util.ArrayList;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.File;
    public class ReadInto2DArrayExample {
        public static void main(String[] args) {
            ArrayList array = new ArrayList();
            char [][] twoDimesionArray = null;
            try
                JFileChooser fileChooser = new JFileChooser();
                if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
                    File file = fileChooser.getSelectedFile();
                    BufferedReader reader = new BufferedReader(new FileReader(file));
                    String data;
                    //Read from file
                    while ((data = reader.readLine()) != null)
                        //Convert data to char array and add into array
                        array.add(data.toCharArray());
                    reader.close();
                    //Creating a 2D char array base on the array size
                    twoDimesionArray = new char [array.size()][];
                    //Convert array from ArrayList to 2D array
                    for (int i = 0; i < array.size(); i++)
                        twoDimesionArray[i] = (char [])array.get(i);
                    //Test the 2D Array
                    for (int y = 0; y < twoDimesionArray.length; y++)
                        char [] temp = twoDimesionArray[y];
                        for (int x = 0; x < temp.length; x ++ )
                            System.out.print(temp[x]);
                        System.out.println("");
            catch (Exception ex)
                ex.printStackTrace();
    }

  • Reading a txt file into a text member with BuddyAPI.

    Hi I have this:
    mFile =_movie.path &"TheTEXT.txt"
    theFile = baShell("open", mFile, "", "", "normal")
    which opens a txt file in note pad. I don't have an idea on how to do this with API to be opened into a txt member.
    Thanks
    Brian

    You don't need Buddy API to import text (which is what you appear to be trying to do) - just set the filename of an existing (or new) text member to the file:
    -- tTextMember = _movie.newMember(#text)
    tTextMember.filename = _movie.path & "TheText.txt"
    tText = tTextMember.text

  • Problem reading .txt-file into JTable

    My problem is that I�m reading a .txt-file into a J-Table. It all goes okay, the FileChooser opens and the application reads the selected file (line). But then I get a Null Pointer Exception and the JTable does not get updated with the text from the file.
    Here�s my code (I kept it simple, and just want to read the text from the .txt-file to the first cell of the table.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.util.*;
    import java.lang.*;
    import java.io.*;
    public class TeamTable extends JFrame implements ActionListener, ItemListener                {
    static JTable table;
         // constructor
    public TeamTable()                {
    super( "Invoermodule - Team Table" );
    setSize( 740, 365 );
              // setting the rownames
    ListModel listModel = new AbstractListModel()                     {
    String headers[] = {"Team 1", "Team 2", "Team 3", "Team 4", "Team 5", "Team 6", "Team 7", "Team 8", "Team 9",
    "Team 10", "Team 11", "Team 12", "Team 13", "Team 14", "Team 15", "Team 16", "Team 17", "Team 18"};
    public int getSize() { return headers.length; }
    public Object getElementAt(int index) { return headers[index]; }
              // add listModel & rownames to the table
              DefaultTableModel defaultModel = new DefaultTableModel(listModel.getSize(),3);
              JTable table = new JTable( defaultModel );
              // setting the columnnames and center alignment of table cells
              int width = 200;
              int[] vColIndex = {0,1,2};
              String[] ColumnName = {"Name Team", "Name Chairman", "Name Manager"};
              TableCellRenderer centerRenderer = new CenterRenderer();          
              for (int i=0; i < vColIndex.length;i++)          {
                             table.getColumnModel().getColumn(vColIndex).setHeaderValue(ColumnName[i]);
                             table.getColumnModel().getColumn(vColIndex[i]).setPreferredWidth(width);
                             table.getColumnModel().getColumn(vColIndex[i]).setCellRenderer(centerRenderer);
              table.setFont(new java.awt.Font("Dialog", Font.ITALIC, 12));
              // force the header to resize and repaint itself
              table.getTableHeader().resizeAndRepaint();
              // create single component to add to scrollpane (rowHeader is JList with argument listModel)
              JList rowHeader = new JList(listModel);
              rowHeader.setFixedCellWidth(100);
              rowHeader.setFixedCellHeight(table.getRowHeight());
              rowHeader.setCellRenderer(new RowHeaderRenderer(table));
              // add to scroll pane:
              JScrollPane scroll = new JScrollPane( table );
              scroll.setRowHeaderView(rowHeader); // Adds row-list left of the table
              getContentPane().add(scroll, BorderLayout.CENTER);
              // add menubar, menu, menuitems with evenlisteners to the frame.
              JMenuBar menubar = new JMenuBar();
              setJMenuBar (menubar);
              JMenu filemenu = new JMenu("File");
              menubar.add(filemenu);
              JMenuItem open = new JMenuItem("Open");
              JMenuItem save = new JMenuItem("Save");
              JMenuItem exit = new JMenuItem("Exit");
              open.addActionListener(this);
              save.addActionListener(this);
              exit.addActionListener(this);
              filemenu.add(open);
              filemenu.add(save);
              filemenu.add(exit);
              filemenu.addItemListener(this);
    // ActionListener for ActionEvents on JMenuItems.
    public void actionPerformed(ActionEvent e) {       
         String open = "Open";
         String save = "Save";
         String exit = "Exit";
              if (e.getSource() instanceof JMenuItem)     {
                   JMenuItem source = (JMenuItem)(e.getSource());
                   String x = source.getText();
                        if (x == open)          {
                             System.out.println("open file");
                        // create JFileChooser.
                        String filename = File.separator+"tmp";
                        JFileChooser fc = new JFileChooser(new File(filename));
                        // set default directory.
                        File wrkDir = new File("C:/Documents and Settings/Erwin en G-M/Mijn documenten/Erwin/Match Day");
                        fc.setCurrentDirectory(wrkDir);
                        // show open dialog.
                        int returnVal =     fc.showOpenDialog(null);
                        File selFile = fc.getSelectedFile();
                        if(returnVal == JFileChooser.APPROVE_OPTION) {
                        System.out.println("You chose to open this file: " +
                   fc.getSelectedFile().getName());
                        try          {
                             BufferedReader invoer = new BufferedReader(new FileReader(selFile));
                             String line = invoer.readLine();
                             System.out.println(line);
                             // THIS IS WHERE IT GOES WRONG, I THINK
                             table.setValueAt(line, 1, 1);
                             table.fireTableDataChanged();
                        catch (IOException ioExc){
                        if (x == save)          {
                             System.out.println("save file");
                        if (x == exit)          {
                             System.out.println("exit file");
    // ItemListener for ItemEvents on JMenu.
    public void itemStateChanged(ItemEvent e) {       
              String s = "Item event detected. Event source: " + e.getSource();
              System.out.println(s);
         public static void main(String[] args)                {
              TeamTable frame = new TeamTable();
              frame.setUndecorated(true);
         frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
              frame.addWindowListener( new WindowAdapter()           {
                   public void windowClosing( WindowEvent e )                {
         System.exit(0);
    frame.setVisible(true);
    * Define the look/content for a cell in the row header
    * In this instance uses the JTables header properties
    class RowHeaderRenderer extends JLabel implements ListCellRenderer           {
    * Constructor creates all cells the same
    * To change look for individual cells put code in
    * getListCellRendererComponent method
    RowHeaderRenderer(JTable table)      {
    JTableHeader header = table.getTableHeader();
    setOpaque(true);
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    setHorizontalAlignment(CENTER);
    setForeground(header.getForeground());
    setBackground(header.getBackground());
    setFont(header.getFont());
    * Returns the JLabel after setting the text of the cell
         public Component getListCellRendererComponent( JList list,
    Object value, int index, boolean isSelected, boolean cellHasFocus)      {
    setText((value == null) ? "" : value.toString());
    return this;

    My problem is that I�m reading a .txt-file into a J-Table. It all goes okay, the FileChooser opens and the application reads the selected file (line). But then I get a Null Pointer Exception and the JTable does not get updated with the text from the file.
    Here�s my code (I kept it simple, and just want to read the text from the .txt-file to the first cell of the table.
    A MORE READABLE VERSION !
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.util.*;
    import java.lang.*;
    import java.io.*;
    public class TeamTable extends JFrame implements ActionListener, ItemListener                {
    static JTable table;
         // constructor
        public TeamTable()                {
            super( "Invoermodule - Team Table" );
            setSize( 740, 365 );
              // setting the rownames
            ListModel listModel = new AbstractListModel()                     {
                String headers[] = {"Team 1", "Team 2", "Team 3", "Team 4", "Team 5", "Team 6", "Team 7", "Team 8", "Team 9",
                "Team 10", "Team 11", "Team 12", "Team 13", "Team 14", "Team 15", "Team 16", "Team 17", "Team 18"};
                public int getSize() { return headers.length; }
                public Object getElementAt(int index) { return headers[index]; }
              // add listModel & rownames to the table
              DefaultTableModel defaultModel = new DefaultTableModel(listModel.getSize(),3);
              JTable table = new JTable( defaultModel );
              // setting the columnnames and center alignment of table cells
              int width = 200;
              int[] vColIndex = {0,1,2};
              String[] ColumnName = {"Name Team", "Name Chairman", "Name Manager"};
              TableCellRenderer centerRenderer = new CenterRenderer();          
              for (int i=0; i < vColIndex.length;i++)          {
                             table.getColumnModel().getColumn(vColIndex).setHeaderValue(ColumnName[i]);
                             table.getColumnModel().getColumn(vColIndex[i]).setPreferredWidth(width);
                             table.getColumnModel().getColumn(vColIndex[i]).setCellRenderer(centerRenderer);
              table.setFont(new java.awt.Font("Dialog", Font.ITALIC, 12));
              // force the header to resize and repaint itself
              table.getTableHeader().resizeAndRepaint();
              // create single component to add to scrollpane (rowHeader is JList with argument listModel)
              JList rowHeader = new JList(listModel);
              rowHeader.setFixedCellWidth(100);
              rowHeader.setFixedCellHeight(table.getRowHeight());
              rowHeader.setCellRenderer(new RowHeaderRenderer(table));
              // add to scroll pane:
              JScrollPane scroll = new JScrollPane( table );
              scroll.setRowHeaderView(rowHeader); // Adds row-list left of the table
              getContentPane().add(scroll, BorderLayout.CENTER);
              // add menubar, menu, menuitems with evenlisteners to the frame.
              JMenuBar menubar = new JMenuBar();
              setJMenuBar (menubar);
              JMenu filemenu = new JMenu("File");
              menubar.add(filemenu);
              JMenuItem open = new JMenuItem("Open");
              JMenuItem save = new JMenuItem("Save");
              JMenuItem exit = new JMenuItem("Exit");
              open.addActionListener(this);
              save.addActionListener(this);
              exit.addActionListener(this);
              filemenu.add(open);
              filemenu.add(save);
              filemenu.add(exit);
              filemenu.addItemListener(this);
    // ActionListener for ActionEvents on JMenuItems.
    public void actionPerformed(ActionEvent e) {       
         String open = "Open";
         String save = "Save";
         String exit = "Exit";
              if (e.getSource() instanceof JMenuItem)     {
                   JMenuItem source = (JMenuItem)(e.getSource());
                   String x = source.getText();
                        if (x == open)          {
                             System.out.println("open file");
                        // create JFileChooser.
                        String filename = File.separator+"tmp";
                        JFileChooser fc = new JFileChooser(new File(filename));
                        // set default directory.
                        File wrkDir = new File("C:/Documents and Settings/Erwin en G-M/Mijn documenten/Erwin/Match Day");
                        fc.setCurrentDirectory(wrkDir);
                        // show open dialog.
                        int returnVal =     fc.showOpenDialog(null);
                        File selFile = fc.getSelectedFile();
                        if(returnVal == JFileChooser.APPROVE_OPTION) {
                        System.out.println("You chose to open this file: " +
                   fc.getSelectedFile().getName());
                        try          {
                             BufferedReader invoer = new BufferedReader(new FileReader(selFile));
                             String line = invoer.readLine();
                             System.out.println(line);
                             // THIS IS WHERE IT GOES WRONG, I THINK
                             table.setValueAt(line, 1, 1);
                             table.fireTableDataChanged();
                        catch (IOException ioExc){
                        if (x == save)          {
                             System.out.println("save file");
                        if (x == exit)          {
                             System.out.println("exit file");
    // ItemListener for ItemEvents on JMenu.
    public void itemStateChanged(ItemEvent e) {       
              String s = "Item event detected. Event source: " + e.getSource();
              System.out.println(s);
         public static void main(String[] args)                {
              TeamTable frame = new TeamTable();
              frame.setUndecorated(true);
         frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
              frame.addWindowListener( new WindowAdapter()           {
                   public void windowClosing( WindowEvent e )                {
         System.exit(0);
    frame.setVisible(true);
    * Define the look/content for a cell in the row header
    * In this instance uses the JTables header properties
    class RowHeaderRenderer extends JLabel implements ListCellRenderer           {
    * Constructor creates all cells the same
    * To change look for individual cells put code in
    * getListCellRendererComponent method
    RowHeaderRenderer(JTable table)      {
    JTableHeader header = table.getTableHeader();
    setOpaque(true);
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    setHorizontalAlignment(CENTER);
    setForeground(header.getForeground());
    setBackground(header.getBackground());
    setFont(header.getFont());
    * Returns the JLabel after setting the text of the cell
         public Component getListCellRendererComponent( JList list,
    Object value, int index, boolean isSelected, boolean cellHasFocus)      {
    setText((value == null) ? "" : value.toString());
    return this;

  • Also problem read txt files into JTable

    hello,
    i used the following method to load a .txt file into JTable
    try{
                        FileInputStream fin = new FileInputStream(filename);
                        InputStreamReader isr = new InputStreamReader(fin);
                        BufferedReader br =  new BufferedReader(isr);
                        StringTokenizer st1 = new StringTokenizer(br.readLine(), "|");
                        while( st1.hasMoreTokens() )
                             columnNames.addElement(st1.nextToken());
                        while ((aLine = br.readLine()) != null)
                             StringTokenizer st2 = new StringTokenizer(aLine, "|");
                             Vector row = new Vector();
                             while(st2.hasMoreTokens())
                                  row.addElement(st2.nextToken());
                             data.addElement( row );
                        br.close();
                        }catch(Exception e){ e.printStackTrace(); }
                   //colNum = st1.countTokens();
                   model = new DefaultTableModel(data,columnNames);
                   table.setModel(model);but there is a problem : if cell A's location is (4,5),and its left neighbour,that is, cell(4,4) is blank (the value is ""), the the cell A's value will be displayed in cell(4,4).if cell(4,3) is also blank ,the cell A's value will be displayed in cell(4,3).that is,the non-blank value will be displayed in the first blank cell of the line.
    how can i solve it?Please give me some helps or links.
    Thank u very much!

    Or, use the String.split(..) method to tokenize the data
    Or, use my SimpleTokenizer class which you can find by using the search function.

  • Load an existing Berkeley DB file into memory

    Dear Experts,
    I have created some Berkeley DB (BDB) files onto disk.
    I noticed that when I issue key-value retrievals, the page faults are substantial, and the CPU utilization is low.
    One sample of the time command line output is as follow:
    1.36user 1.45system 0:10.83elapsed 26%CPU (0avgtext+0avgdata 723504maxresident)k
    108224inputs+528outputs (581major+76329minor)pagefaults 0swaps
    I suspect that the bottleneck is the high frequency of file I/O.
    This may be because of page faults of the BDB file, and the pages are loaded in/out of disk fairly frequently.
    I wish to explore how to reduce this page fault, and hence expedite the retrieval time.
    One way I have read is to load the entire BDB file into main memory.
    There are some example programs on docs.oracle.com, under the heading "Writing In-Memory Berkeley DB Applications".
    However, I could not get them to work.
    I enclosed below my code:
    --------------- start of code snippets ---------------
    /* Initialize our handles */
    DB *dbp = NULL;
    DB_ENV *envp = NULL;
    DB_MPOOLFILE *mpf = NULL;
    const char *db_name = "db.id_url";   // A BDB file on disk, size  66,813,952
    u_int32_t open_flags;
    /* Create the environment */
    db_env_create(&envp, 0);
    open_flags =
    DB_CREATE | /* Create the environment if it does not exist */
    DB_INIT_LOCK | /* Initialize the locking subsystem */
    DB_INIT_LOG | /* Initialize the logging subsystem */
    DB_INIT_MPOOL | /* Initialize the memory pool (in-memory cache) */
    DB_INIT_TXN |
    DB_PRIVATE; /* Region files are not backed by the filesystem.
    * Instead, they are backed by heap memory. */
    * Specify the size of the in-memory cache.
    envp->set_cachesize(envp, 0, 70 * 1024 * 1024, 1); // 70 Mbytes, more than the BDB file size of 66,813,952
    * Now actually open the environment. Notice that the environment home
    * directory is NULL. This is required for an in-memory only application.
    envp->open(envp, NULL, open_flags, 0);
    /* Open the MPOOL file in the environment. */
    envp->memp_fcreate(envp, &mpf, 0);
    int pagesize = 4096;
    if ((ret = mpf->open(mpf, "db.id_url", 0, 0, pagesize)) != 0) {
    envp->err(envp, ret, "DB_MPOOLFILE->open: ");
    goto err;
    int cnt, hits = 66813952/pagesize;
    void *p=0;
    for (cnt = 0; cnt < hits; ++cnt) {
    db_pgno_t pageno = cnt;
    mpf->get(mpf, &pageno, NULL, 0, &p);
    fprintf(stderr,"\n\nretrieve %5d pages\n",cnt);
    /* Initialize the DB handle */
    db_create(&dbp, envp, 0);
    * Set the database open flags. Autocommit is used because we are
    * transactional.
    open_flags = DB_CREATE | DB_AUTO_COMMIT;
    dbp->open(dbp, // Pointer to the database
    NULL, // Txn pointer
    NULL, // File name -- NULL for inmemory
    db_name, // Logical db name
    DB_BTREE, // Database type (using btree)
    open_flags, // Open flags
    0); // File mode. defaults is 0
    DBT key,data; int test_key=103456;
    memset(&key, 0, sizeof(key));
    memset(&data, 0, sizeof(data));
    key.data = (int*)&test_key;
    key.size = sizeof(test_key);
    dbp->get(dbp, NULL, &key, &data, 0);
    printf("%d --> %s ", *((int*)key.data),(char*)data.data );
    /* Close our database handle, if it was opened. */
    if (dbp != NULL) {
    dbp->close(dbp, 0);
    if (mpf != NULL) (void)mpf->close(mpf, 0);
    /* Close our environment, if it was opened. */
    if (envp != NULL) {
    envp->close(envp, 0);
    /* Final status message and return. */
    printf("I'm all done.\n");
    --------------- end of code snippets ---------------
    After compilation, the code output is:
    retrieve 16312 pages
    103456 --> (null) I'm all done.
    However, the test_key input did not get the correct value retrieval.
    I have been reading and trying this for the past 3 days.
    I will appreciate any help/tips.
    Thank you for your kind attention.
    WAN
    Singapore

    Hi Mike
    Thank you for your 3 steps:
    -- create the database
    -- load the database
    -- run you retrievals
    Recall that my original intention is to load in an existing BDB file (70Mbytes) completely into memory.
    So following your 3 steps above, this is what I did:
    Step-1 (create the database)
    I have followed the oracle article on http://docs.oracle.com/cd/E17076_02/html/articles/inmemory/C/index.html
    In this step, I have created the environment, set the cachesize to be bigger than the BDB file.
    However, I have some problem with the code that opens the DB handle.
    The code on the oracle page is as follow:
    * Open the database. Note that the file name is NULL.
    * This forces the database to be stored in the cache only.
    * Also note that the database has a name, even though its
    * file name is NULL.
    ret = dbp->open(dbp, /* Pointer to the database */
    NULL, /* Txn pointer */
    NULL, /* File name is not specified on purpose */
    db_name, /* Logical db name. */
    DB_BTREE, /* Database type (using btree) */
    db_flags, /* Open flags */
    0); /* File mode. Using defaults */
    Note that the open(..) API does not include the BDB file name.
    The documentation says that this is so that the API will know that it needs an in-memory database.
    However, how do I tell the API the source of the existing BDB file from which I wish to load entirely into memory ?
    Do I need to create another DB handle (non-in-memory, with a file name as argument) that reads from this BDB file, and then call DB->put(.) that inserts the records into the in-memory DB ?
    Step-2 (load the database)
    My question in this step-2 is the same as my last question in step-1, on how do I tell the API to load in my existing BDB file into memory?
    That is, should I create another DB handle (non-in-memory) that reads from the existing BDB file, use a cursor to read in EVERY key-value pair, and then insert into the in-memory DB?
    Am I correct to say that by using the cursor to read in EVERY key-value pair, I am effectively warming the file cache, so that the BDB retrieval performance can be maximized ?
    Step-3 (run your retrievals)
    Are the retrieval API, e.g. c_get(..), get(..), for the in-memory DB, the same as the file-based DB ?
    Thank you and always appreciative for your tips.
    WAN
    Singapore

  • How to load a BDB file into memory?

    The entire BDB database needs to reside in memory for performance reasons, it needs to be in memory all the time, not paged in on demand. The physical memory and virtual process address space are large enough to hold this file. How can I load it into memory just before accessing the first entry? I've read the C++ API reference, and it seems that I can do the following:
    1, Create a DB environment;
    2, Call DB_ENV->set_cachesize() to set a memory pool large enough to hold the BDB file;
    3, Call DB_MPOOLFILE->open() to open the BDB file in memory pool of that DB environment;
    4, Create a DB handle in that DB environment and open the BDB file (again) via this DB handle.
    My questions are:
    1, Is there a more elegant way instead of using that DB environment? If the DB environment is a must, then:
    2, Does step 3 above load the BDB file into memory pool or just reserve enough space for that file?
    Thanks in advance,
    Feng

    Hello,
    Does the documentation on "Memory-only or Flash configurations" at:
    http://download.oracle.com/docs/cd/E17076_02/html/programmer_reference/program_ram.html
    answer the question?
    From there we have:
    By default, databases are periodically flushed from the Berkeley DB memory cache to backing physical files in the filesystem. To keep databases from being written to backing physical files, pass the DB_MPOOL_NOFILE flag to the DB_MPOOLFILE->set_flags() method. This flag implies the application's databases must fit entirely in the Berkeley DB cache, of course. To avoid a database file growing to consume the entire cache, applications can limit the size of individual databases in the cache by calling the DB_MPOOLFILE->set_maxsize() method.
    Thanks,
    Sandra

  • Reading a text File into a JTextArea

    I know this is really basic question, but what is the best and/or simplest way to read text from a .txt file into a JTextArea? I'm new to Java and any help anyone can provide would be greatly appreciated.

    it should be in quotes only if it is a string repersentation of a String class.
    FileReader reader = new FileReader("readme.txt");
    quotes are not needed if you write it this way
    String filename = "readme.txt";
    FileReader reader = new FileReader(filename);
    ...remember that String is a class and not a data type, it is also a special case in java where the class can act like a datatype in declarations.
    I don't think anything else can behave like this in java
    String text = "sometext";
    "sometext".equals(text);
    this returns true.

  • How can I load a .TXT file into a dynamic text box?

    I am sure that many people know how to load a .txt file into
    a dynamic text box. But I do not. I want to be able to reference a
    txt file from the server into the text box. So that when I change
    the text file it changes in the flash movie without even editing
    the flash file itself. Thank you.

    http://www.oman3d.com/tutorials/flash/loading_external_text_bc/
    I think this is the simplest way to go :)

  • Assistance in Reading a .txt file

    I'm newbie on Java and I have a problem
    I'm doing a homework on Systems and I need to read a .txt file [It would be on the same folder as the Java file].
    The catch is that I have to read by Lines, Each Line could have as much as 3 words[tokens] as little as one.
    I also have to read the characters on the words/tokens to identify if they are valid.
    I have thought of 2 ways of doing this.
    Reading ALL the line and dividing the words by the Spaces.
    Or read the words by tokens and then having a flag to know when the line jumps.
    Example of the text file:
    ORG %011010
    Et1 equ $ffFF
    ;Comentary # 1
    dos LDAA @456
    END
    I hope I'm being clear.
    Now, I'm not looking to have my homework done for me, but I am looking for some pointers.
    I've tried the Scanner class but I just don't know the right methods I guess... I've also heard the Token StringTokenizer class works. But I have no clue.
    Someone could give me pointers? which Class would be the right one and which methods?
    I've been Struggling with this all week.
    Help will be really appreciated.

    I would use the Scanner class to read an entire line. If you don't know what methods to use then read the Java API and the explanation for each method of the Scanner class. Write some code to experiment and see what those methods do. Then when you have an entire line I would use String.split as StringTokenizer is/has been deprecated.

  • Interesting ? @ servlet reading a txt file

    hi friends,
    i need ur help for one interesting problem i m facing.
    I want to read a txt file and wanna display the text from that file into an html, using a servlet.A txt file contains sentences( words with spaces in between ).When servlet reads the file, it is reading the whole sentence ,but while displaying that sentence, it is just showing the first word of the sentence.
    html is not able to read the space between the words.
    so what do i suppose to do now.
    waiting for ur replies.......
    thanx
    amit

    hi friends ,
    i m giving the code , just give it a try//
    This is a servlet ---------------------------------------
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    public class AdminGraphServlet extends HttpServlet
    Properties ht;
    FileInputStream fin;
    FileOutputStream fout;
    String s15,st;
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException,ServletException
    ht = new Properties();
    try
    fin = new FileInputStream("Data.txt");
    catch(FileNotFoundException e)
    System.out.println("FileNotFound");
    try
    if(fin != null)
    ht.load(fin);
    s15 = (String)ht.get("title");
    fin.close();
    catch(IOException e)
    System.out.println("Error Reading File");
    PrintWriter out = res.getWriter();
    res.setContentType("text/html");
    out.println("<html><body>");
    out.println("<form method=post action=http://localhost:8080/servlet/MyServlet>");
    out.println("<table><tr>");
    out.println("<tr><td>Title</td>");
    out.println("<td><Input Type=Text name=title value="+ s15 +"> </td></tr>");
    out.println("</table>");
    out.println("<input type=submit name=submit value=submit>");
    out.println("<input type=hidden name=check value=save>");
    out.println("</form>");
    out.println("</body></html>");
    public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
    String Scheck = req.getParameter("check");
    PrintWriter out1 = res.getWriter();
    String ttl = req.getParameter("title");
    if(Scheck.equals("save"))
    ht.put("title",ttl);
    fout = new FileOutputStream("Data.txt");
    ht.store(fout,"Data");
    fout.close();
    out1.println("<html><body>");
    out1.println("<h1>Stored This Data Successfully</h1>");
    out1.println("</html></body>");
    txt file is having a line
    title=Are you smart enough?
    The servlet should display this sentence in a text box.
    But it is displaying only "Are".
    still waiting...
    have nice time..
    amit

  • Add .txt files into .zip file

    Hello friends,
    Any buddy knows how to add ".txt" files into ".zip" format through the ABAP code. 
    Thanks in advance.

    Hi Murali,
    You can use the method in the class CL_ABAP_GZIP to zip your file and then download it using GUI_DOWNLOAD.
    data: zip type ref to cl_abap_zip,
          result type xstring.
    create object zip.
    zip->add( name = some_file content = content ).
    result = zip->save( ).
    Also you can check this thread as well.
    How to Download data in Zip folder
    Re: UNZIP file from ABAP
    Hope this will help.
    Regards,
    Ferry Lianto
    Please reward points if helpful.

  • Reading in text file into strings

    Hi,
    I'm new to the reading in data part of java and I can't work out a good way to read in a .txt file and then store each line of the txt file into strings.
    I think I'm probably just missing something obvious but if anyone can help :D!
    Thanks,
    Bex

    Look up Scanner in Java 1.5, or BufferedReader in Java 1.4.

  • Convert .txt file into .xml file

    Hello,
    How do i convert an .txt file into an .xml file using labVIEW function?.
    Also i do i extract the header from the text file.
    My file format is mentioned in attached .txt file.
    Also I need to extract the header from the converted .xml file.
    Anticipating reply
    Attachments:
    Example.txt ‏1 KB

    There is no automatic mechanism for converting a .txt file to XML in any language. You have to define the XML schema and then write the code to generate the XML file. You could also read in your text file into some form of structure and then use the Flatten to XML functions to use the NI XML schema. If you need to use your own XML schema then you would need to use the XML Parser VIs to generate your XML file. Alternatively, you could use LabXML or JKI's EasyXML Toolkit.

Maybe you are looking for

  • Separate Intercompany Matching Application

    Hello Experts, I have created a separate intercompany application of type Finance. In this application I have created an account dimension for this application which is different than the account dimension in the Finance application. Now the problem

  • Physical path for XML created of program RTXDART_PT

    Hi guys, where does the program RTXDART_PT save its XML file? What is the physical path location? Thank you!

  • Windows Can't access after program bugs out.

    Anytime I run a program and the program bugs out on me it will then start coming up with the "windows cannot access" error. It only happens if the program bugs out. At that point i'll uninstall the program and reinstall it but it still will catch it

  • Not updated the windows tital

    Hi all, could any one help on this.. In project manager respensibility-> project list->Controler tab There is a create textBox when I select issue and click the go button then the header title of the page displayed as Create Issue:Issue, But the clie

  • How to fix the header of the table(advanced table) on the top?

    I just start making oaf, so I feel difficult in case it is easy for you. My question is: How to fix the header of the table(advanced table) to see on the top of the OAF page, even though I scroll to the bottom of the page? I need your help. All my be