Read a file and maintain a file pointer?

Hi,
I need to read a file which has about 1000 records(approx).I need to read 10 records from the beginning of the file and then give the 10 records to a different java process and then continue extracting records for every 10.So how do I save the filepointer and then continue read from the 11th record and then 21st record and so on?
Remember I don't know the total number of records in the file,but know where exactly I have to extract,I mean the trailer info.
also, Is there a way to store a file pointer for a particular position in the file and then continue reading the file from the same place by using the saved filepointer?
any idea?
also,If I save a filepointer as long value and open the file later using randomaccess file,and seek using this saved long value,will there be any change in the position of the file?will this differ in unix and windows?I mean the file pointer?
--Robert

Maybe this will make things clearer. Don't be intimidated, it's not really hardimport java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
import java.io.*;
public class Test extends JFrame {
    static final long RECORD_SIZE = 8;
    RandomAccessFile rf;
    JTextArea jta = new JTextArea();
    JTextField jtf = new JTextField();
    Random r = new Random();
    public Test() {
     try { rf = new RandomAccessFile("rtest.dat", "rw"); }
     catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); System.exit(1); }
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     Container content = getContentPane();
     // Set up the GUI
     content.add(new JScrollPane(jta), BorderLayout.CENTER);
     jtf.setPreferredSize(new Dimension(100,20));
     content.add(jtf, BorderLayout.NORTH);
     JPanel buttonPanel = new JPanel();
     content.add(buttonPanel, BorderLayout.SOUTH);
     JButton add10 = new JButton("Add 10");
     buttonPanel.add(add10);
     add10.addActionListener(new ActionListener() {   // Add 10 listener
         public void actionPerformed(ActionEvent ae) {
          try {
              rf.seek(rf.length());                // seek to end
              for(int i = 0; i < 10; i++)          // write 10 recs
                   rf.writeDouble(r.nextDouble()*1000000.);
          catch (IOException ioe) { ioe.printStackTrace(); }
          jta.setText("10 records appended");
          showStats();                        // show current statistics
     JButton list10 = new JButton("List Next 10");
     buttonPanel.add(list10);
     list10.addActionListener(new ActionListener() {    // list 10 listener
         public void actionPerformed(ActionEvent ae) {
          jta.setText(null);
          try {
              for(int i = 0; i < 10; i++) {
               if (rf.getFilePointer()<rf.length()) {  // if not eof
                   long recNo = rf.getFilePointer()/RECORD_SIZE;
                   jta.append(""+recNo+") "+Double.toString(rf.readDouble())+"\n");
               } else jta.append("(eof)\n");
          } catch (IOException ioe) { ioe.printStackTrace(); }
          showStats();                        // show current location/size
     JButton random10 = new JButton("List Random 10");
     buttonPanel.add(random10);
     random10.addActionListener(new ActionListener() {   // list 10 random records
         public void actionPerformed(ActionEvent ae) {
          jta.setText(null);
          try {
              for(int i = 0; i < 10; i++) {
               // Get a rendom record number
               int recNo = r.nextInt((int)(rf.getFilePointer()/RECORD_SIZE));
               // seek to it
               rf.seek(recNo*RECORD_SIZE);
               // read record, add to textarea
               jta.append(""+recNo+") "+Double.toString(rf.readDouble())+"\n");
          } catch (IOException ioe) { ioe.printStackTrace(); }
          showStats();
     buttonPanel.add(random10);
     JButton rewind = new JButton("Rewind");
     buttonPanel.add(rewind);
     rewind.addActionListener(new ActionListener() {  // rewind listener
         public void actionPerformed(ActionEvent ae) {
          jta.setText(null);
          try {
              rf.seek(0);                     // move to beginning
          } catch (IOException ioe) { ioe.printStackTrace(); }
          jta.setText("Rewound");
          showStats();                    // show size/location
     buttonPanel.add(rewind);
     showStats();
     setSize(600,500);
     show();
    private void showStats() {
     try {
         jtf.setText("Cnt="+(rf.length()/RECORD_SIZE)+
               ", Cur="+(rf.getFilePointer()/RECORD_SIZE));
     } catch (IOException ioe) { ioe.printStackTrace(); }
    public static void main(String[] args) { new Test(); }
}

Similar Messages

  • VBScript to read the content of a .csv file and delete old files mentioned in the .csv

    I have a Windows 2003 file server.
    I have generated a report in .csv format, about the files which are older than 1 year.
    I need a VBScript to read the .csv file and delete the files which are enlisted there.
    Can someone please help me with this?

    Look into the "Learn" link above.  There are resources and instructions on how to write VBScript code.  Look into how to use the FileSystemObject.
    ¯\_(ツ)_/¯

  • How to read multiple files and generate multiple files

    Dear all, I would like to process some LTE measurement files. Currently I can only load a single file and process the data and save it to a single binary file. Since I would like to run the code continously, could someone show me how I can modify the code to load multiple files and specify multiple files to save the process the data please? I have attached the code to the question. Many thanks for your help.
    Attachments:
    RF Analyze IQ File.vi ‏46 KB

    There is no official "bin" format and I am confused by some of your statements:
    Kiwibunny wrote:
    Currently I can only load a single file and process the data and save it to a single binary file. Since I would like to run the code continously, could someone show me how I can modify the code to load multiple files and specify multiple files to save the process the data please? I have attached the code to the question. Many thanks for your help.
    What you could do is use "list folder" with *.bin as pattern, and use a FOR loop and iterate over all *.bin files found in a selected folder.
    In any case, your code uses some weird constructs and you seem to do way to much. Are you using "continuous run" mode? Don't!
    Use a proper state machine instead ot these stalling loops. Why do you need to query the queue after each enqueue? Why do you need a queue at all?
    LabVIEW Champion . Do more with less code and in less time .

  • How do I open png files and maintain transparency?

    How do I open png files and maintain transparency?  I have many image files I had hoped to manage with aperture along with my photos.  I find that it wants to display them with a black bacground( they were designed for white) and when I want to edit that is kept even when I open with a psd format.  What do I do?
    Thanks

    and when I want to edit that is kept even when I open with a psd format.  What do I do?
    Transparency and layers are not supported in Aperture. You can import png-files or psd files with a transparent background and export the originals unchanged, but as soon as you edit them, the transparent background will be lost.
    Aperture is an application to manage photos and not graphics compositions, sorry.
    -- Léonie

  • Publish option that creates only 1 file and maintains the interactivity? CP 5

    When I publish my project in Flash, it creates a folder with the .sfw file, the standard (JS file) and all my .f4v (videos).
    I tried to publish my projet in the f4v format, but like you probably know, I loose all the interactivity (roll-overs, buttons, etc..).
    Is there a better way to publish my stuff without having many files and maintains the interactivity?
    Thank You!

    exe?
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • I converted aif files to mp3 files in I tunes so I could put them on a flash drive.  Now when I transfer an album to the flash drive I get both the aif files and the mp3 files in the flash drive.  How do I get the iTunes to only copy the smaller file?

    I converted aif files to mp3 files in iTunes so I could put them on a flash drive.  Now when I transfer an album to the flash drive I get both the aif files and the mp3 files on the flash drive.  How do I get the iTunes to only copy the smaller file?

    My suggestion to use the smart playlist was more along the lines of making one list with rules to show everything in your library as long as it was kind "mpeg" (= mp3).
    Smart playlists cannot be edited manually, only by changing the rules.  You can use them as the basis for another smart playlist though.
    There is added overhead to using smart playlists, so don't go overboard.

  • I am running 4.0.1 and when I download something the Download box stays blank-even though I have selected in General Preferences 'Show the downloads window when downloading a file' AND selected 'Save files to Downloads'....???

    I am running 4.0.1 and when I download something the Download box stays blank-even though I have selected in General Preferences 'Show the downloads window when downloading a file' AND selected 'Save files to Downloads'....???

    In Firefox Options / Privacy be sure "Remember download history" is checked. To see all of the options on that panel, "Firefox will" must be set to "Use custom settings for history".
    To find your OS information, on your Windows desktop, right-click the My Computer icon, choose Properties, under System on that small window is info about your OS.
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''

  • PDF file and Microsoft Word files

    I love all the big improvements apple is making to their product lines. But I am a practical person who needs to open pdf. files and Microsoft Word files on the go. That is why I will still pick a Treo, Dash, and any other pda over the Iphone. When is apple going to make a real war against PDA's and produce these kinds of software? This would make the Iphone the ultimate phone.

    Actually you CAN store them on your phone -- you need to download the free program FileMarkMaker (Its in versiontracker for mac, don't know if it is available for PC users)
    It allows you to attach any PDF within a URL address and save it as a bookmark, and sync it to your iPhone. You can then read it anytime (you don't need an internet connection) by going to the name of the link you created for the file in Safari. Works perfectly -- I have everything from Maps of the subway stations for the cities I visit to manuals and documents on it.
    Just one caveat -- you can't search or use other features from within that Safari page - it will just crash the safari application -- you need to change to a blank safari page before you can use google or other safari features.

  • Zip files and Adobe Acrobat files

    Hello all,
    I have a couple of kinda distinct questions that I wanted to ask. I hope I've chosen the right sub-forum to post them in. My questions are
    1) when I try to unzip a .zip file in my Documents folder I get the following error message
    "Archive Utility - unable to unarchive "CdnEnergy.zip" into "Documents". (Error 1 - Operation not permitted.)"
    ditto if I move it to the Desktop and try there. This doesn't seem to be a 'space' problem as my computer is very new and I haven't loaded it up with lots of stuff. I have unzipped this file before (admittedly not on a Mac).
    2) How can I set Adobe Acrobat to be the default application for .pdf files so that when I click on a pdf file it's opened by Adobe Reader rather than the Mac Viewer? I know I can select Adobe with a Ctrl+click, but can I set it so that it's always the default?
    Thanks very much for your help,
    Eoghan

    Welcome to the Discussions!
    The first problem is not obvious, but I would suggest using Disk Utility to repair permissions. Also, you could download the free Stuffit Expander to have an alternate unzip program.
    The second problem is easy. In the Finder, select a pdf file and then select File->Get Info. In the window that appears, select the Acrobat as the Open With application and select the option to always use this application.
    bd

  • Problems converting PDF to MS Word document.  I successfuly converted 4 files and now subsequent files generate a "conversion failure" error when attempting to convert the file.  I have a large manuscript and I separated each chapter to assist with the co

    Problems converting PDF to MS Word document.  I successfully converted 4 files and now subsequent files generate a "conversion failure" error when attempting to convert the file.  I have a large manuscript and I separated each chapter to assist with the conversion; like I said, first 4 parts no problem, then conversion failure.  I attempted to convert the entire document and same result.  I specifically purchased the export to Word feature.  Please assist.  I initially had to export the Word Perfect document into PDF and attempting to go from PDF to MS Word.

    Hi sdr2014,
    I'm sorry to hear your conversion process has stalled. It sounds as though the problem isn't specific to one file, as you've been unable to convert anything since the first four chapters converted successfully.
    So, let's try this:
    If you're converting via the ExportPDF website, please log out, clear the browser cache, and then log back in. If you're using Reader, please choose Help > Check for Updates to make sure that you have the most current version installed.
    Please let us know how it goes.
    Best,
    Sara

  • Burn music files and a pdf file?

    Is it possible to burn some music files and a pdf file on the same CD using iTunes? If not, maybe using some other software?
    Numbers

    J Cabaniss wrote:
    Is it possible to burn some music files and a pdf file on the same CD using iTunes? If not, maybe using some other software?
    iTunes can only burn files that are in its library, so forget about PDFs.
    Yes it can be done with other programs, using a data (not audio) CD format.

  • .xml file and iTunes library files are missing from the music folder

    I recently made a second itunes library on my external hd, today when I open itunes and choose this library, the .xml file and itunes music file are invisible or translucent, therefore I can't open my library. But when I go to my music folder they are missing. Another odd thing is that all my music is still in the folder. Is there a way to re-open my library w/o re-importing all my music? Can I some how get a new itunes library file?
      Mac OS X (10.4.10)  

    This is not an answer but I have the same problem. From time to time I clone my music drive to an external drive for back up. When I do, I burn a copy of the album artwork folder, iTunes Music folder, iTunes Library.itl, iTunes Music Libraru.xml, and iTunes Library file to CDRW. This is so I can copy them into the music folder in my user home drive of my laptop then hook up the external and have access my library. Trouble is the .xml file and iTunes library files don't always show up when I go to the iTunes folder in my Music folder. There either is a blank where they should be or the names appear with no icon and when I click to select, that dissappers too. I thought I had a solve by exiting iTunes and letting it save everything. It seems to bring the .xml file back but not the itunes Library file. Any thoughts?

  • I take a .NEF file and a .JPG file with every click. When I transfer the files using a flash drive to another computer I never get all of the files to transfer. I get some of the .NEF and some of the .JPGs but not all

    I take a .NEF file and a .JPG file with every click. When I transfer the files using a flash drive to another computer I never get all of the files to transfer. I get some of the .NEF and some of the .JPGs but not all. How come?

    If you're exporting a project then you'll only get the images in that project. Also if any of the masters are referenced then you won't get those masters unless you check Consolidate masters into exported library
    It might be best if you started from the beginning and explained what it is your are trying to do and how you're going about doing it. Also a description of you're hardware/software setup would be helpful.

  • I have backed up my iPad  using iTunes to windows 8 Lenora laptop but I could not find my files and play video files  in my laptop.

    I have backed up my iPad  using iTunes to windows 8 Lenora laptop but I could not find my files and play video files  in my laptop

    You cannot access files in the backup on your computer.
    Do you mean that you synced with iTunes and transferred your purchased videos and app documents? If that is what you mean, what videos are you talking about? If they are videos that you took with the iPad, they do not sync to iTunes. What files?
    What exactly are you trying to do? Details please.

  • Recently switched from powermac to mac pro5 2x2.66GHz 6 -core xeon   running FCP 7 on OS 10.6.8  exporting qt files and rendering project files now takes longer than my old machine   looking at activity mon and % of user is aroun 6 and % of idle around 42

    recently switched from powermac to mac pro5 2x2.66GHz 6 -core xeon   running FCP 7 on OS 10.6.8  exporting qt files and rendering project files now takes longer than my old machine   looking at activity mon and % of user is aroun 6 and % of idle around 42  are all the cores being used with FCP7?

    johnnyapplesod wrote:
    exporting qt files and rendering project files now takes longer than my old machine
    It's because the PowerMac G5 had HUGE bandwidth with a fat BUS on each processsor so they could run hard, hot and heavy.
    It's not so with the Intel processors which are multi-core and share a common bus thus bottleneck.
    The newer Intel processors can do more work on the CPU, but when it comes to in/out they are s-l-o-w.
    I've had a wickedly fast dual processor (not dual core) G5, RAID 0 pair of 10,000 RPM drives as boot and a fast video card, I could do a lot very very fast.
    You'll likely have to upgrade to Final Cut X to get more cores utilized, prepare to cry a little bit, Apple is working on the features they stripped out of it to make amends to pro users who complained loudly. (all over TV too)
    http://www.loopinsight.com/2011/09/20/apple-releases-major-update-to-final-cut-p ro-x-release-demo-version/

Maybe you are looking for

  • Error in loading dmp file

    while loading a.dmp file into oracle in centos using impdp command following errors seen Can any body help me.....? Export: Release 10.2.0.1.0 - Production on Wednesday, 01 November, 2006 1:51:55 Copyright (c) 2003, 2005, Oracle. All rights reserved.

  • Goods receipt at current valid price instead of price in PO

    Hi experts,     My client is starting a new business. He has following requirement for it - Goods receipt should be done at the price valid on Goods receipt day For Example : PO is raised on 1.1.2011. On that day, Cost/MRP is 100. Goods receipt is do

  • Does anyone help me in understanding single ended and diff ended signal? and

    iam using daqpad-mio-16xe-50,in this daqpad if i want to use diff ended signal,lets say channel 0 then i connect +ve wire in 0 pin and -ve wire in 8 pin. till now is alright,but manual say that groung the -ve pin in the al ground or in case mentioned

  • Running Browser calling method'CL_GUI_FRONTEND_SERVICES' in the background.

    Hello SAP Gurus My intention is to shutdown and restart communication channels on PI side. To do this externally, we can send a URL with right parameters. I have written a simple ABAP  code to do this by calling the method 'CL_GUI_FRONTEND_SERVICES '

  • I need to keep my messages.

    I need to keep all of my emails.  Mac Mail keeps deleting the messages in my Trash (which makes sense, I guess) even though I have checked NEVER delete under preferences.  How can I set up my mail so that A. my trash is never emptied, or B. the delet