1

Possible Duplicate:
Resize an image in Java - Any Open Source Library ?

InputStream is = new FileInputStream(file);
    long length = file.length();
    // if (length > Integer.MAX_VALUE) {
    // File is too large
    // }
    byte[] bytes = new byte[(int) length];

if i enter large image....it should accept but size should be reduced

Community
  • 1
  • 1
Rockin
  • 723
  • 4
  • 25
  • 51
  • 7
    Truncate the file? Compress it with zip? If it's something analog like a picture or music file, you can compress it with something lossy.... what do you need? –  Apr 12 '11 at 09:06
  • Why you don't use a buffer and read data in small portions ? – StKiller Apr 12 '11 at 09:09

2 Answers2

1
Umesh K
  • 13,436
  • 25
  • 87
  • 129
0

First, you should use a buffer and read the data in buffer-size increments, otherwise you will probably have problems when the data is big.

Second, as suggested by other users, you should use compression, or, since we are talking about images, you can always downsample it as a last resource, if you are in a very memory constrained environment.

Luis Miguel Serrano
  • 5,029
  • 2
  • 41
  • 41