package com.ruoyi.fuzhou.utils.hj1239;
|
|
import java.io.*;
|
import java.util.ArrayList;
|
|
/**
|
* 文件读取工具类
|
*/
|
public class FileReadUtils {
|
public static void main(String[] args) throws Exception {
|
byte[] bytes = readFromByteFile("D:\\福州项目\\ftp\\VEXJJYEY937103845_25032121");
|
String content = bytesToHex(bytes);
|
content = content.replace("aaaabbbbccccaaaa", "aaaabbbb,ccccaaaa");
|
String[] src = content.split(",");
|
for (int i = 0; i < src.length; i++) {
|
String items = src[i];
|
}
|
System.out.println(src);
|
}
|
|
public static byte[] readFromByteFile(String pathname) throws IOException {
|
File filename = new File(pathname);
|
BufferedInputStream in = new BufferedInputStream(new FileInputStream(filename));
|
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
|
byte[] temp = new byte[1024];
|
int size = 0;
|
while ((size = in.read(temp)) != -1) {
|
out.write(temp, 0, size);
|
}
|
in.close();
|
byte[] content = out.toByteArray();
|
return content;
|
}
|
|
/**
|
* 字节数组转16进制
|
*
|
* @param bytes 需要转换的byte数组
|
* @return 转换后的Hex字符串
|
*/
|
public static String bytesToHex(byte[] bytes) {
|
StringBuffer sb = new StringBuffer();
|
for (int i = 0; i < bytes.length; i++) {
|
String hex = Integer.toHexString(bytes[i] & 0xFF);
|
if (hex.length() < 2) {
|
sb.append(0);
|
}
|
sb.append(hex);
|
}
|
return sb.toString();
|
}
|
|
public ArrayList<String> readFromTextFile(String pathname) throws IOException {
|
ArrayList<String> strArray = new ArrayList<String>();
|
File filename = new File(pathname);
|
InputStreamReader reader = new InputStreamReader(new FileInputStream(filename));
|
BufferedReader br = new BufferedReader(reader);
|
String line = "";
|
line = br.readLine();
|
while (line != null) {
|
strArray.add(line);
|
line = br.readLine();
|
}
|
return strArray;
|
}
|
|
}
|