• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

Can Java applet read & write binary files

If java can read & write binary files, I need to see a small example of this please. Thanks
0
oualide
Asked:
oualide
  • 3
  • 3
  • 2
  • +1
1 Solution
 
imladrisCommented:
Absolutely. The simplest form would be something like:

FileInputStream fi=new FileInputStream(name);
byte b[]=new byte[30];
fi.read(b,0,30);
fi.close();

There is a FileOutputStream which has a method to write byte arrays. If you need reading and writing simultaneously you can use the RandomAccessFile which has similar methods for read and write.

0
 
imladrisCommented:
Note: The read and write methods listed above will get the sequence of bytes (30 in the above example) in the file. Converting that information to primitive entities may require some work on your part. For instance, if you want to get integers out  of the file: how many bytes are used to represent them? Are they encoded in little-endian or big-endian order? Similar and more complicated questions can arise for floating point numbers.

0
 
evijayCommented:
For an applet, use getResourceAsStream with url as parameter. For writing applets, you need to sign the applets
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
evijayCommented:
For an applet, use getResourceAsStream with url as parameter. For writing binary files from applets, you need to sign the applets
0
 
oualideAuthor Commented:
How to sign an applet and wher to find info. about this please.
Thanks.
0
 
evijayCommented:
0
 
oualideAuthor Commented:
0
 
diakovCommented:
0
 
oualideAuthor Commented:
thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now