acc
wlcacc
全部博文(170)
FireWorkflow(0)
Oracle(9)
ExtJS(19)
面试题集锦(5)
其他(2)
JavaScript(22)
DIV+CSS(12)
网页制作(0)
网络技术(2)
ASP(1)
Tomcat(1)
OS(0)
DB(0)
Hibernate(5)
Java(0)
Spring(1)
Struts(2)
Fireworks(15)
Windows(7)
Java(30)
MySQL(11)
2014年(7)
2010年(2)
2009年(62)
2008年(25)
2007年(67)
2006年(7)
knife800
alunfirs
格伯纳
Bsolar
浪花小雨
chengccy
qingfeng
laishiwa
Iqcw1368
分类:
2007-05-07 16:10:11
import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException;public class ReadFile { private static void readFile1(String fileName) { try { Scanner scanner = new Scanner(new File(fileName)); scanner.useDelimiter(System.getProperty("line.separator"));
//line.separator:获取系统换行符. System.out.println("姓名 年龄 时间 标记 "); while (scanner.hasNext()) { parseLine(scanner.next()); } scanner.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } private static void parseLine(String line) { Scanner lineScanner = new Scanner(line); lineScanner.useDelimiter("\\s*,\\s*"); //可以修改useDelimiter参数以读取不同分隔符分隔的内容 String name = lineScanner.next(); int age = lineScanner.nextInt(); String idate = lineScanner.next(); boolean isCertified = lineScanner.nextBoolean(); System.out.println(name + " " + age + " "+idate+" " + isCertified+" " ); } public static void main(String[] args) { // if (args.length != 1) { // System.err.println("usage: java ReadHuman file location"); // System.exit(0); // } readFile1("D:\\test.txt"); }}
//line.separator:获取系统换行符.
System.out.println("姓名 年龄 时间 标记 "); while (scanner.hasNext()) { parseLine(scanner.next()); } scanner.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } private static void parseLine(String line) { Scanner lineScanner = new Scanner(line); lineScanner.useDelimiter("\\s*,\\s*"); //可以修改useDelimiter参数以读取不同分隔符分隔的内容 String name = lineScanner.next(); int age = lineScanner.nextInt(); String idate = lineScanner.next(); boolean isCertified = lineScanner.nextBoolean(); System.out.println(name + " " + age + " "+idate+" " + isCertified+" " ); } public static void main(String[] args) { // if (args.length != 1) { // System.err.println("usage: java ReadHuman file location"); // System.exit(0); // } readFile1("D:\\test.txt"); }}
test.txt文件:
张三 ,28 ,FEB-01 ,true李四 ,22 ,DEC-02 ,false王五 ,21 ,DEC-03 ,false赵六 ,25 ,DEC-04 ,true
上一篇:SELECT:改变背景颜色+链接网页
下一篇:java中时间格式SimpleDateFormat的使用学习
登录 注册