TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
- /**
- * 判断文件是否为图片文件(GIF,PNG,JPG)
- *
- * @param srcFileName
- * @return
- */
- public static boolean isImage(String srcFileName) {
- FileInputStream imgFile = null;
- byte[] b = new byte[10];
- int l = -1;
- try {
- imgFile = new FileInputStream(srcFileName);
- l = imgFile.read(b);
- imgFile.close();
- } catch (Exception e) {
- return false;
- }
- if (l == 10) {
- byte b0 = b[0];
- byte b1 = b[1];
- byte b2 = b[2];
- byte b3 = b[3];
- byte b6 = b[6];
- byte b7 = b[7];
- byte b8 = b[8];
- byte b9 = b[9];
- if (b0 == (byte) "G" && b1 == (byte) "I" && b2 == (byte) "F") {
- return true;
- } else if (b1 == (byte) "P" && b2 == (byte) "N" && b3 == (byte) "G") {
- return true;
- } else if (b6 == (byte) "J" && b7 == (byte) "F" && b8 == (byte) "I"&& b9 == (byte) "F") {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- }
复制代码
源码下载:http://file.javaxxz.com/2014/10/30/235656109.zip |
|