数据文件包解析工具类 RandomAccessFile
public class ReadTextFile {
public static void main(String[] args) {
pic2txt();
parseFrmFile();
//url2pic();
}
private static void parseFrmFile() {
File floder = new File("D:\\shuaka");
if(floder.isDirectory()){
File files[] = floder.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if(name!=null&&name.endsWith(".frm")){
return true;
}else{
return false;
}
}
});
RandomAccessFile in = null;
for (int i = 0; i < files.length; i++) {
try {
in = new RandomAccessFile(files[i],"r");
parseFrmImagesAndData(in);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
private static void parseFrmImagesAndData(RandomAccessFile in) throws IOException{
String line = null;
while((line = in.readLine())!=null){
//System.out.println(line);
if(line.contains("image-length")){
int image_length = Integer.parseInt(line.split(":")[1]);
System.out.println("图片长度:"+image_length);
//in.seek(in.getFilePointer());
byte b[] = new byte[(int) in.length()];
in.read(b);
File image = new File("D:\\vehicle_data\\11.jpg");
FileOutputStream out = new FileOutputStream(image);
out.write(b);
out.flush();
out.close();
}else if(line.contains("data-length")){
String data_length = String.valueOf(line.split(":")[1]);
String struct = in.readLine();
System.out.println("数据长度:"+data_length);
File data = new File("D:\\vehicle_data\\"+System.currentTimeMillis()+".text");
FileOutputStream out = new FileOutputStream(data);
out.write(struct.getBytes());
out.flush();
out.close();
}
}
}
private static void pic2txt() {
try {
InputStream in = getInputStream("http://190.112.28.72/BK002/XRGSUMFTF/0/2018/05/24/BK002XRGSUMFTF020180524111324972.jpg");
FileOutputStream out = new FileOutputStream(new File("D:/shuaka/11.txt"));
System.out.println("image-length"+":"+in.available());
out.write(("image-length"+":"+in.available()).getBytes());
out.write("\n".getBytes());
byte[] b = new byte[1024];
int len = 0;
while((len=in.read(b))!=-1){
out.write(b,0,len);
}
out.flush();
out.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void url2pic(){
String url ="http:xx.xx.xx.xx//test/24972.jpg";
try {
URL imgurl = new URL(url);
InputStream in = new DataInputStream(imgurl.openStream());
FileOutputStream out = new FileOutputStream(new File("D:/shuaka/url2pic.jpg"));
byte[] b = new byte[1024];
int len = 0;
while((len=in.read(b))!=-1){
out.write(b,0,len);
}
out.flush();
out.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static InputStream getInputStream(String url){
try {
URL imgurl = new URL(url);
return new DataInputStream(imgurl.openStream());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
数据文件包解析工具类 RandomAccessFile的更多相关文章
- Android 包信息工具类
/** AndroidInfoUtils:安卓游戏包信息工具类**/ 1 public class AndroidInfoUtils { @SuppressWarnings("uncheck ...
- java中文件操作的工具类
代码: package com.lky.pojo; import java.io.BufferedReader; import java.io.BufferedWriter; import java. ...
- spring mvc 文件上传工具类
虽然文件上传在框架中,已经不是什么困难的事情了,但自己还是开发了一个文件上传工具类,是基于springmvc文件上传的. 工具类只需要传入需要的两个参数,就可以上传到任何想要上传的路径: 参数1:Ht ...
- spring boot 文件上传工具类(bug 已修改)
以前的文件上传都是之前前辈写的,现在自己来写一个,大家可以看看,有什么问题可以在评论中提出来. 写的这个文件上传是在spring boot 2.0中测试的,测试了,可以正常上传,下面贴代码 第一步:引 ...
- 读取EXCEL文档解析工具类
package test;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException ...
- 文件上传工具类 UploadUtil.java
package com.util; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import ja ...
- Java中创建操作文件和文件夹的工具类
Java中创建操作文件和文件夹的工具类 FileUtils.java import java.io.BufferedInputStream; import java.io.BufferedOutput ...
- Java操作文件夹的工具类
Java操作文件夹的工具类 import java.io.File; public class DeleteDirectory { /** * 删除单个文件 * @param fileName 要删除 ...
- //读取配置文件(属性文件)的工具类-ConfigManager
package com.pb.news.util; import java.io.IOException;import java.io.InputStream;import java.sql.Resu ...
随机推荐
- echarts使用——柱状图
开发中,做报表统计的时候,很容易用到echarts实现折线图.饼状图.柱状图的绘制,使用echarts插件很简单,官网有教程实例,但主要是这些图需要的数据格式的转换. 我的柱状图实现效果: 第一部分 ...
- C语言I博客作业02
这个作业属于那个课程 C语言程序设计I 这个作业要求在哪 https://edu.cnblogs.com/campus/zswxy/CST2019-3/homework/8656 我在这个课程的目标 ...
- 2017CCSP-01 五子棋 简单模拟
题面和数据 对于每个空格,先定义一个变量cnt=0,表示空格填充后对五子数量的变化,四个方向进行两边搜索,设对于每个方向连续的白棋子分别为\(wa\),\(wb\),有以下几种情况. \(wa> ...
- Windows定时备份Mysql数据库
1.新建批处理文件bat(随意命名:如auto_backup_mysql_data.bat) 2.在批处理文件里添加如下命令 %1 mshta vbscript:createobject(" ...
- [Note] 解决使用Workerman和apache创建wss服务时出现的 Error during WebSocket handshake: net::ERR_RESPONSE_HEADERS_TRUNCATED
使用apache代理生成的wss服务常出现 Error during WebSocket handshake: net::ERR_RESPONSE_HEADERS_TRUNCATED 的问题,但多刷新 ...
- js实现烟花效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue3.0的安装使用
关于旧版本 Vue CLI 的包名称由 vue-cli 改成了 @vue/cli. 如果你已经全局安装了旧版本的 vue-cli (1.x 或 2.x),你需要先通过 npm uninstall vu ...
- SQL SERVER数据库三种数据插入方式
数据插入:INSERT INTO A(CBM,CMC) VALUES('1','测试')--单条数据插入INSERT INTO A(CBM,CMC)SELECT '1','测试'--单条数据插入INS ...
- 【C语言笔记】#define与typedef的区别
1.#define define是预处理指令,在编译时不进行任何检查,只进行简单的替换 宏定义的一般形式为: #define 宏名 字符串 这里所说的字符串是一般意义上的字符序列,不要和C语言中的字符 ...
- 代码审计-EasyCMS
cms来源AWD线下攻防平台题目. 链接:https://pan.baidu.com/s/1eUkyRspQmsv-0fIBby8ZlQ 提取码:tywa 失效可以联系我 0x01 文件上传漏 ...