Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to read to a file position using FileInputStream and alter a specific record.

Posted on 2003-12-12
4
Medium Priority
?
347 Views
Last Modified: 2008-03-06
I am using FileInputStream to find a position in a file and would like to edit a perticular record when all criteria is met. How do I change from a FileInputStream to a FileOutputStream without loosing my file pointer?
 
0
Comment
Question by:rayskelton
  • 2
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 500 total points
ID: 9927798
use a randomaccessfile instead...
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9927804
I don't think you can do this without reading from the input and writing to the output until you hit the record you want, then writing the new record and finally continuing reading/writing (ie. effectively copying the file).

If you want to jump in to the middle of a file and do editing, you should probably be using a RandomAccessFile.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9927805
Hee hee ;-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9927809
;-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question