10
aaa aaa aaa
bbb bbb bbb
ccc ccc ccc
ddd ddd ddd
我有一个文本文件,我试图用制表符分隔符读取.每当我读取文件时,我在 10 之后得到一个 arrayindexoutofbound 错误.我在网上搜索,发现我必须在 后面添加一个 -1,但我仍然得到同样的错误.
I have a textfile that Im trying to read with tab delimiters. whenever i read the file, i get an arrayindexoutofbound error after the 10. i search online and found that i have to add a -1 behind the but i still get the same error.
try{
Scanner scan = new Scanner(new File("1.txt"));
String line="";
int readline = Integer.parseInt(scan.nextLine());//
while (scan.hasNextLine())
{
line = scan.nextLine();
if(line.equals("ccc"))
{
break;
}
String[] split=line.split(" ");
array.add(split);
}
如果你使用Scanner这里不需要split,你可以使用next()这里如下
If you are use Scanner here no need to split, you can use next() here as follows
Scanner sc=new Scanner(new FileReader("D:\test.txt"));
while (sc.hasNextLine()){
System.out.println(sc.next());
}
这篇关于读取制表符分隔的文本文件 java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在 JTextPane 中的组件周围环绕文本?How to wrap text around components in a JTextPane?(如何在 JTextPane 中的组件周围环绕文本?)
MyBatis,如何获取插入的自动生成密钥?[MySql]MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何获取插入的自动生成密钥?[MySql])
在 Java 中插入 Oracle 嵌套表Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java:如何将 CLOB 插入 oracle 数据库Java: How to insert CLOB into oracle database(Java:如何将 CLOB 插入 oracle 数据库)
为什么 Spring-data-jdbc 不保存我的 Car 对象?Why does Spring-data-jdbc not save my Car object?(为什么 Spring-data-jdbc 不保存我的 Car 对象?)
使用线程逐块处理文件Use threading to process file chunk by chunk(使用线程逐块处理文件)