• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sequentail file

 
Joe Wiesenfeld
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need some help, I'm new and confused.
How do I write a sequentail file consisting of over fifty fields
(It's ok if they are all strings). In c i would use a structure. What's compatible in Java.
I tried writing class as an object using ObjectOuputStrean. And I'm getting alot of garbage in my output.
Please help it would be greatly appreciated.
Thank you
 
sankarsv
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I also got same problem. Then, i used DataOutputStream. It worked. I wrote strings into the file.The code goes like this....
fos = new FileOutputStream(path);
dos = new DataOutputStream(fos);
dos.writeBytes("Hello Dear Friend");
Sankar
Originally posted by Joe Wiesenfeld:
I need some help, I'm new and confused.
How do I write a sequentail file consisting of over fifty fields
(It's ok if they are all strings). In c i would use a structure. What's compatible in Java.
I tried writing class as an object using ObjectOuputStrean. And I'm getting alot of garbage in my output.
Please help it would be greatly appreciated.
Thank you

 
Joe Wiesenfeld
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks greatly appreciated.
Now how do I use a structure like to pass in.
Originally posted by sankarsv:
Hi,
I also got same problem. Then, i used DataOutputStream. It worked. I wrote strings into the file.The code goes like this....
fos = new FileOutputStream(path);
dos = new DataOutputStream(fos);
dos.writeBytes("Hello Dear Friend");
Sankar

 
sankarsv
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
U can write objects into file using ObjectOutputStream as u were doing before. Whatever u see in file is not garbage but characters understandable by ObjectInputStream. ( I think its UTF characters). For ur eyes, it looks garbage. For verification, use ObjectInputStream and read the file and print the outputs. You will get same data what u wrote into the file.
Hope this info helps you.
Sankar
Originally posted by Joe Wiesenfeld:
Thanks greatly appreciated.
Now how do I use a structure like to pass in.

 
Joe Wiesenfeld
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is this will be read by other systems which not necessarally be written in Java to have the ObjectInputStream available to them.
Thanks
Originally posted by sankarsv:
Hi,
U can write objects into file using ObjectOutputStream as u were doing before. Whatever u see in file is not garbage but characters understandable by ObjectInputStream. ( I think its UTF characters). For ur eyes, it looks garbage. For verification, use ObjectInputStream and read the file and print the outputs. You will get same data what u wrote into the file.
Hope this info helps you.
Sankar

 
sankarsv
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Override toString method in the class which u want to write into the file. Inside the method u need to convert the data of the class into string. Then, use DataOutputStream to write. I think this is what u need to do.
Sankar
Originally posted by Joe Wiesenfeld:
The problem is this will be read by other systems which not necessarally be written in Java to have the ObjectInputStream available to them.
Thanks

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!