zoukankan      html  css  js  c++  java
  • JAVA 解析TXT文本

    package file;

    import java.io.BufferedReader;

    import java.io.File;

    import java.io.FileInputStream;

    import java.io.InputStreamReader;

    import java.util.Date;

    public class ImportFile {    

        public static void main(String[] args) {  

           System.out.println(new Date());  

           String path = "E:\数据.txt";  //文件路径

           File file = new File(path);  

           if(file.exists() && file.isFile()){

              try{

                 InputStreamReader read = new InputStreamReader(new FileInputStream(file),"GBK");  //设置文字编码

                BufferedReader bufferRead = new BufferedReader(read);

                String lineText = null;     

             while(bufferRead.readLine() != null){

                  lineText = bufferRead.readLine();

                  String data[] = lineText.split(" "); //本文件中按制表符分割

                  for(String x : data){

                   System.out.println(x);

                  }

                }

                read.close();

            }catch(Exception e){

             e.printStackTrace();

          }

      }

      System.out.println(new Date());  

    }

    }

  • 相关阅读:
    typeScript 之(3) 类型
    TypeScript 采坑 记录
    typeScript 之(2) 环境部署
    typeScript 之(1) 简介
    webpack 之(29) optiization配置详解
    webpack 之(28) devServer配置详解
    webpack 之(27) resolve配置详解
    webpack 之(26) module配置详解
    docker中的Mysql数据卷与持久化
    TCP三次握手四次挥手
  • 原文地址:https://www.cnblogs.com/StanLong/p/6380959.html
Copyright © 2011-2022 走看看