File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
Java in General
Image extension and mimetype
Joined: Oct 12, 2011
Oct 12, 2011 11:51:02
Is there any way i could find out the image extension and mimtype from stream(or uploaded file)?
is = dataHandler.getInputStream();
bi = ImageIO.read(is);
System.out.println("width: " + bi.getWidth());
System.out.println("height: " + bi.getHeight());
System.out.println("type" + bi.getType());
I can use the Magic.getMagicmatch to get the mime type?
mimeType = Magic.getMagicMatch(BYTESTREAM, false).getMimeType();
but, is there any way to get the extension from uploaded file using
Joined: Oct 27, 2005
Oct 12, 2011 12:21:05
Use String's lastIndexOf method to find the last location of a dot, then return the substring from that location + 1. Be careful that lastIndexOf will return -1 when no dot is found, which also means there is no extension.
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions
How To Answer Questions
I agree. Here's the link:
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Image extension and mimetype
How to get the path of an Uploaded file?
Image Upload - Jsp or servlet
Issue with Copy and Paste from external source to applet.
problem with if-condition
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013