📄 fileutil.java
字号:
package com.gzrealmap.oa;
/**
* <p>Title: RealOA2003a</p>
* <p>Description: OA二期开发</p>
* <p>Copyright: Copyright (c) 2002-2003</p>
* <p>Company: RealMap.cc</p>
* @author Mulder
* @version V2003a
*/
import java.io.*;
public class FileUtil {
public final static String jpeg = "jpeg";
public final static String jpg = "jpg";
public final static String gif = "gif";
public final static String tiff = "tiff";
public final static String tif = "tif";
public final static String png = "png";
public final static String xml = "xml";
public final static String xsl = "xsl";
public final static String doc = "doc";
public final static String txt = "txt";
public final static String xsd = "xsd";
public final static String dtd = "dtd";
public final static String htm = "htm";
public final static String html = "html";
public static final int sizeLimit = 5120000;
public static byte[] stream2Bytes(InputStream ins) throws Exception {
byte[] result;
byte[] b = new byte[sizeLimit];
int size = 0;
int i;
while ( (i = ins.read()) != -1) {
b[size] = (byte) i;
if (size >= sizeLimit)
throw new IOException("File size exceeded size limit!");
size++;
}
result = new byte[size];
System.arraycopy(b, 0, result, 0, size);
//System.out.println(HexUtils.convert(result));
//System.out.print(byteToHex(result));
return result;
}
public static String stream2Hex(InputStream ins) throws Exception {
StringBuffer hex = new StringBuffer();
int size = 0;
int i;
while ( (i = ins.read()) != -1) {
char c = toHexChar(i);
System.out.print(c);
hex.append(c);
/*
hex.append((toHexChar(i >>> 4) & 0x0F));
hex.append(toHexChar(i & 0x0F));
*/
if (size >= sizeLimit)
throw new IOException("File size exceeded size limit!");
size++;
}
return hex.toString();
}
/**
* method to convert a byte to a hex string.
*
* @param data the byte to convert
* @return String the converted byte
*/
public static String byteToHex(byte[] data) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < data.length; i++) {
buf.append(toHexChar( (data[i] >>> 4) & 0x0F));
buf.append(toHexChar(data[i] & 0x0F));
//System.out.println(i);
}
return buf.toString();
}
/**
* Convenience method to convert an int to a hex char.
*
* @param i the int to convert
* @return char the converted char
*/
public static char toHexChar(int i) {
if ( (0 <= i) && (i <= 9)) {
return (char) ('0' + i);
}
else {
return (char) ('A' + (i - 10));
}
}
/**
* 用于删除文件名的后缀
*/
public static final String getFileBasicName(String filename) {
if (filename != null) {
int endIndex = filename.lastIndexOf(".");
if (endIndex > 0) {
filename = filename.substring(0, endIndex);
}
return filename;
}
return null;
}
/*
* Get the extension of a file.
*/
public static String getExtension(File f) {
String ext = null;
String s = f.getName();
int i = s.lastIndexOf('.');
if (i > 0 && i < s.length() - 1) {
ext = s.substring(i + 1).toLowerCase();
}
return ext;
}
public static final String byteToHex(byte byte0) {
char ac[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'
};
char ac1[] = {
ac[byte0 >> 4 & 0xf], ac[byte0 & 0xf]
};
return new String(ac1);
}
public static void main(String[] args) {
System.out.println(FileUtil.getFileBasicName("cc.abc"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -