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("\t"); //本文件中按制表符分割
for(String x : data){
System.out.println(x);
}
}
read.close();
}catch(Exception e){
e.printStackTrace();
}
}
System.out.println(new Date());
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步