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的更多相关文章

  1. Android 包信息工具类

    /** AndroidInfoUtils:安卓游戏包信息工具类**/ 1 public class AndroidInfoUtils { @SuppressWarnings("uncheck ...

  2. java中文件操作的工具类

    代码: package com.lky.pojo; import java.io.BufferedReader; import java.io.BufferedWriter; import java. ...

  3. spring mvc 文件上传工具类

    虽然文件上传在框架中,已经不是什么困难的事情了,但自己还是开发了一个文件上传工具类,是基于springmvc文件上传的. 工具类只需要传入需要的两个参数,就可以上传到任何想要上传的路径: 参数1:Ht ...

  4. spring boot 文件上传工具类(bug 已修改)

    以前的文件上传都是之前前辈写的,现在自己来写一个,大家可以看看,有什么问题可以在评论中提出来. 写的这个文件上传是在spring boot 2.0中测试的,测试了,可以正常上传,下面贴代码 第一步:引 ...

  5. 读取EXCEL文档解析工具类

    package test;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException ...

  6. 文件上传工具类 UploadUtil.java

    package com.util; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import ja ...

  7. Java中创建操作文件和文件夹的工具类

    Java中创建操作文件和文件夹的工具类 FileUtils.java import java.io.BufferedInputStream; import java.io.BufferedOutput ...

  8. Java操作文件夹的工具类

    Java操作文件夹的工具类 import java.io.File; public class DeleteDirectory { /** * 删除单个文件 * @param fileName 要删除 ...

  9. //读取配置文件(属性文件)的工具类-ConfigManager

    package com.pb.news.util; import java.io.IOException;import java.io.InputStream;import java.sql.Resu ...

随机推荐

  1. 使用maven开发javaweb项目

    想重新学习一下java web的知识,之前也学习过一些但是也没有用在开发中所以也忘的七七八八了,因为从事Android开发免不了要与服务器打交道,有时候想自己写一个小DEMO需要服务器的时候感觉真是很 ...

  2. MySQL 分页查询优化

    有时在处理偏移量非常大的分页时候查询时,例如LIMIT 1000,10这样的查询,这时MySQL需要查询1010条记录然后只返回最后10条,前面1000条记录都被抛弃,这样的代价非常高.要优化这种查询 ...

  3. volatile 关键字的作用

    简介Java 语言提供了一种稍弱的同步机制,即 volatile 变量,用来确保将变量的更新操作通知到其他线程.volatile 变量具备两种特性:变量可见性.禁止重排序. 作为同步锁在访问 vola ...

  4. asp.netcore 自动挡Docker Nginx Redis(滴滴滴,自动挡)

    前言 上一章介绍了Docker通过多条命令创建启动运行Docker容器,由此可见这样一个个去创建单独的容器也是相当麻烦的,比如要在某个复杂项目中用DB.缓存.消息等等,这样我们还要去一个个再创建,为此 ...

  5. Unity进阶技巧 - RectTransform详解

    前言 最近要做UI,有时候需要在代码中调整改变UI控件的属性,比如位置.大小等,然而在NGUI里面,控制UI控件的位置等属性的是RectTransform这个组件,这个组件继承自Transform组件 ...

  6. MySQL-时区导致的时间前后端不一致

    背景 今天早上刚上班,就被同事提示,程序的日期处理有问题.数据库里日期为:2019-05-21 11:00:00 而前端显示的日期为:2019-05-21 16:00:00 分析 那肯定是和时区相关了 ...

  7. JNA的步骤、简单实例以及资料整理

    1.步骤 1.编写dll文件,放入项目的bin目录(在window上是dll文件,在Linux上是so文件,dll和so都是由C程序生成)  2.新建接口继承Library  3.加载对应的dll或者 ...

  8. Java匹马行天下之教你用学汉语式方法学编程语言

    Java匹马行天下之教你用学汉语式方法学编程语言 前言: 前段时间接连更新了带小白从入门到了解的几篇博客: <Java匹马行天下之编程常识知多少> <Java匹马行天下之走进编程的殿 ...

  9. Android中三种常用解析XML的方式(DOM、SAX、PULL)简介及区别

    XML在各种开发中都广泛应用,Android也不例外.作为承载数据的一个重要角色,如何读写XML成为Android开发中一项重要的技能.今天就由我向大家介绍一下在Android平台下几种常见的XML解 ...

  10. 某CTF平台一道PHP代码审计

    这道题不是说太难,但是思路一定要灵活,灵活的利用源码中给的东西.先看一下源码. 首先要理解大意. 这段源码的大致的意思就是,先将flag的值读取放在$flag里面. 后面再接受你输入的值进行判断(黑名 ...