一个文本文件 每行的格式为
数字i 字母c 数字j 字符串S
现在想读入这个文本文件 然后将每行的数字 字母 数字 字符串分别分开输出
请教如何操作(不要用tio软件包)
数字i 字母c 数字j 字符串S
现在想读入这个文本文件 然后将每行的数字 字母 数字 字符串分别分开输出
请教如何操作(不要用tio软件包)
解决方案 »
- 火龙果大侠:求教一正则表达式
- 异常Exception in thread "main" java.lang.NullPointerException 怎么解决。
- 一个新手问题
- 问啥是正则式
- java读取文本文件中的第10个字节并放到变量C中
- 如何在一个弧形里填充渐变色?
- 请问如何在java中导如入用3DMAX做成的.MAX模型???
- 什么是脚本语言,还有什么其他类型的语言?
- JCreator里为什么找不到java.servlet.* java.servlet.http.* 类 ,求助!
- 笨鸟提问:Java都能什么?
- 请问 JAVA是用什么语言写的
- ScrollPane的布局到底怎么弄啊,好奇怪的现象。
/**
* <pre>
* [機 能] 文件读取。
* [説 明] 按照指定路径下的文件读取,并输出
* </pre>
* @param strFileName 文件名
* @param strDirectory 文件路经
* @throws Exception
*/
public static void read(final String strDirectory,
final String strFileName) throws Exception {
File infile = null;
BufferedReader reader = null;
String line = null;
try {
infile = new File(strDirectory, strFileName);
reader = new BufferedReader((new InputStreamReader(
new FileInputStream(infile))));
while ((line = reader.readLine()) != null) { // 读取一行
String[] datas = line.split(" "); // 这里假设你的数据是用空格分开的
for (String str : datas) {
System.out.println(str); // 输出每个数据,数字i 字母c 数字j 字符串S...
}
}
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (Exception e) {
throw e;
}
}
}
try {
FileReader fr = new FileReader("c:/test.txt");
Scanner scanner = new Scanner(fr);
while (true){
if (scanner.hasNext()){
System.out.println(scanner.next());
}else if (scanner.hasNextInt()){
System.out.println(scanner.nextInt());
}else{
break;
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}