基本 I/O 令牌查询
BufferedReader br = new BufferedReader(new FileReader("data/Catalog.txt"));
String line="";
arrayList =new ArrayList();
while((line = br.readLine())!=null)
{
// System.out.println(line);
StringTokenizer st = new StringTokenizer(line);
while(st.hasMoreTokens())
{
//System.out.println(st.nextToken());
arrayList.add(st.nextToken());
}
}
}
//读取文件时token有什么用?什么是数组列表?
BufferedReader br = new BufferedReader(new FileReader("data/Catalog.txt"));
String line="";
arrayList =new ArrayList();
while((line = br.readLine())!=null)
{
// System.out.println(line);
StringTokenizer st = new StringTokenizer(line);
while(st.hasMoreTokens())
{
//System.out.println(st.nextToken());
arrayList.add(st.nextToken());
}
}
}
//what is the use of token when reading the file? and what is an arraylist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
StringTokenizer
用于将文件中的每一行拆分为单词。单词在每个空格、制表符、换行符、回车符和换行符处被分割。ArrayList
是List
< 的实现/a>,保留其顺序的项目集合。列表中的每个项目都可以通过从零开始的索引进行访问。对于此类问题,我强烈建议您阅读 Java 6 API 文档。它包含您需要了解的有关标准 Java 类行为的所有详细信息。
The
StringTokenizer
is used to split every line in the file into words. The words are splitted at every space, tab character, newline character, carriage-return character and line-feed character.An
ArrayList
is an implementation ofList
, a collection of items that preserves their order. Every item in the list is accessible through a zero-based index.I highly recommend to read the Java 6 API documentation for questions like this. It has every detail you need to know about the behaviour of standard Java classes.
StringTokenizer 会将每一行划分为单词(按空格标记),因此 ArrayList 将包含该文件中存在的所有单词。
StringTokenizer will divide each line into words (tokenizes by space) and because of that ArrayList will have all the words present in that file.
分词器可让您通过分隔符分隔文本。默认情况下使用空格作为分隔符,但您也可以在创建标记生成器时设置它们。只需将它们列在一个字符串中即可。
数组列表是用于保存对象的可扩展容器。
A tokenizer lets you break up the text by delimiters. Whitespace is used by default as delimiters, but you can also set these when you create a tokenizer. Just list them out in a string.
An arraylist is an expandable container for holding objects.