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());  

    }

    }

  • 相关阅读:
    让svn自动更新代码注释中的版本号
    前端开发利器F5
    当inlineblock和textindent遇到IE6,IE7
    DSL与函数式编程
    [译]当Node.js遇上WebMatrix 2
    《大道至简》的读后感
    深度学习之卷积神经网络之一
    ORACLE TRUNC()函数
    oracle rownum
    ORACLE 忽略已有重复值 创建唯一约束
  • 原文地址:https://www.cnblogs.com/StanLong/p/6380959.html
Copyright © 2011-2022 走看看