Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get file position

Posted on 2004-08-30
8
Medium Priority
?
248 Views
Last Modified: 2010-05-18
Hello,

I'm writing a text file. For reasons of convienience I use the PrintWriter object.

My problem is that at certain points during the file write operation I need to know
the current file pointer position. If this was a RandomAccessFile I would simply
do getFilePointer() method.

How do I know which byte position I'm at ?   Is there another way of doing this ?

Thanks.
0
Comment
Question by:kxix
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 11930044
You can by using a "channel".
;JOOP!
0
 
LVL 35

Expert Comment

by:girionis
ID: 11930061
How are you writing the data? Character by character? If yes then you coudl use a counter and count how many characters you write and then save the position somewhere. If you write a String then count the length of the string and get the last position every time. Do likewise for the other constructors (byte array or String with offsets).
0
 
LVL 35

Expert Comment

by:girionis
ID: 11930066
> constructors (byte array or String with offsets).

should be

write method signatures (byte array or String with offsets).
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 24

Accepted Solution

by:
sciuriware earned 500 total points
ID: 11930074
Example I used for input monitoring:

import java.nio.channels.FileChannel;

         FileInputStream fi = new FileInputStream(source);
         FileChannel fic = fi.getChannel();
.....
               position = fic.position();

And so on.

;JOOP!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11930142
>>I need to know the current file pointer position.

Why, may we ask?
0
 

Author Comment

by:kxix
ID: 11949152
The simplest answer seems to be to use a Channel as suggested by "sciuriware".
I therefore accept this answer.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11949161
>> The simplest answer seems to be to use a Channel as suggested by "sciuriware".

Then we you gave just 'C' to he or she ???
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 11949269
Correct English would be:

"Then, why did you just give 'C' to him or her?"

And his opinion is .......  I don't care too much.

;JOOP!
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

636 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