数据文件包解析工具类 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 ...
随机推荐
- Terminal MultipleXer---终端复用器tmux基本使用
Terminal MultipleXer---终端复用器tmux 使用场景:1.scp大文件 2:编译大文件 3:多窗口对比文件 1.安装tmux [root@localhost ~]# yum in ...
- 什么是Affordance?
什么是Affordance? 在人机交互领域中,我们常常提到某个设计的affordance.其中文对应的意思并没有一个统一的意见.Wikipedia2上先这个词被译为“承担特质”或者“环境赋使”(非常 ...
- redis 漏洞造成服务器被入侵-CPU飙升
前言 前几天在自己服务器上搭了redis,准备想着大展身手一番,昨天使用redis-cli命令的时候,10s后,显示进程已杀死.然后又试了几次,都是一样的结果,10s时间,进程被杀死.这个时候我还 ...
- Scala 学习笔记之集合(6)
object CollectionDemo7 { def main(args: Array[String]): Unit = { //数组使用 val arr = Array("red&qu ...
- Django学习之model进阶
一 QuerySet 可切片 使用Python 的切片语法来限制查询集记录的数目 .它等同于SQL 的LIMIT 和OFFSET 子句. >>> Entry.objects.al ...
- spring boot项目下的application.properties中的logging.level设置日志级别
日志级别 trace<debug<info<warn<error<fatal 默认级别为info,即默认打印info及其以上级别的日志,如下: logging.level ...
- ionic3 浏览器端返回
首屏component.ts文件中使用setupBrowserBackButtonBehavior() { // Register browser back button action(s) wind ...
- Typesetting HDU - 6107
Yellowstar is writing an article that contains N words and 1 picture, and the i-th word contains aia ...
- linux 基本操作积累
1 sed 命令,替换含有指定字符的一整行数据 sed -i 's/原字符串/替换后的字符串/g' ./文件名 (此命令会全局替换[整个文件内替换]原字符串) sed -i.bak 's/原字符串/替 ...
- Cohen-Sutherland算法
Cohen-Sutherland算法 本算法又称为编码裁剪算法,算法的基本思想是对每 条直线段分三种情况处理: (1)若点p1和p 2完全在裁剪窗口内 “简取”之 (2)若点p1(x1,y1)和p2( ...