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. ┱Python中关于urllib和urllib2的问题

    python3对urllib和urllib2进行了重构主要拆分成了:1.urllib.request 1.urllib.request.Request(url, data=None, headers= ...

  2. java几个常见的基础错误

    1.String 相等 稍微有点经验的程序员都会用equals比较而不是用 ==,但用equals就真的安全了吗,看下面的代码 user.getName().equals("xiaoming ...

  3. Java中的static(1)【持续更新】——关于Eclipse的No enclosing instance of type ... 错误的理解和改正

    No enclosing instance of type SomeClass is accessible. Must qualify the allocation with an enclosing ...

  4. 基于hash和pushState的网页前端路由实现

    客户端路由 对于客户端(通常为浏览器)来说,路由的映射函数通常是进行一些DOM的显示和隐藏操作.这样,当访问不同的路径的时候,会显示不同的页面组件.客户端路由最常见的有以下两种实现方案:* 基于Has ...

  5. mysql库复制

    一.使用navicate复制mysql库 二.使用命令 通过命令:1.创建新数据库CREATE DATABASE `newdb` DEFAULT CHARACTER SET UTF8 COLLATE ...

  6. PHP 实现get 和 Post 请求

    1 get get请求比较简单,file_get_contents():即可实现 $tmpUrl = "http://测试url"; # get方法获取信息 $rawGetData ...

  7. 编程杂谈——std::vector与List<T>的性能比较

    昨天在比较完C++中std::vector的两个方法的性能差异并留下记录后--编程杂谈--使用emplace_back取代push_back,今日尝试在C#中测试对应功能的性能. C#中对应std:: ...

  8. 用go语言爬取珍爱网 | 第一回

    我们来用go语言爬取"珍爱网"用户信息. 首先分析到请求url为: http://www.zhenai.com/zhenghun 接下来用go请求该url,代码如下: packag ...

  9. 重大升级!SEER见证人,您的节点需要在10月28日前更新

    SEER的区块链底层目前还处于不断完善中.一些新的完善更新会为区块链的基础设施--节点软件添加新的功能.理事会将会就是否接受新的节点版本进行共识投票,如果提案投票通过,将要求所有见证人在指定时间前将节 ...

  10. 生产环境中的kubernetes 优先级与抢占

    kubernetes 中的抢占功能是调度器比较重要的feature,但是真正使用起来还是比较危险,否则很容易把低优先级的pod给无辜kill.为了提高GPU集群的资源利用率,决定勇于尝试一番该feat ...