1.查询文件内容字节长度
public class Demo {
public static void main(String[] args) throws ParseException, IOException {
FileInputStream fileInputStream = new FileInputStream("D:\Desktop\aa.txt");
System.out.println(contentLength(fileInputStream));
}
public static long contentLength(InputStream is) throws IOException {
try {
long size = 0;
byte[] buf = new byte[256];
int read;
while ((read = is.read(buf)) != -1) {
size += read;
}
return size;
}
finally {
try {
is.close();
}
catch (IOException ex) {
}
}
}
}
2. 从给定的字符中删除任意字符
public static String deleteAny(String inString, @Nullable String charsToDelete) {
if (!hasLength(inString) || !hasLength(charsToDelete)) {
return inString;
}
StringBuilder sb = new StringBuilder(inString.length());
for (int i = 0; i < inString.length(); i++) {
char c = inString.charAt(i);
if (charsToDelete.indexOf(c) == -1) {
sb.append(c);
}
}
return sb.toString();
}