基本 I/O 令牌查询

发布于 2025-01-02 01:30:37 字数 501 浏览 3 评论 0原文

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独行侠 2025-01-09 01:30:37

StringTokenizer用于将文件中的每一行拆分为单词。单词在每个空格、制表符、换行符、回车符和换行符处被分割。

ArrayListList< 的实现/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 of List, 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.

前事休说 2025-01-09 01:30:37

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.

那一片橙海, 2025-01-09 01:30:37

分词器可让您通过分隔符分隔文本。默认情况下使用空格作为分隔符,但您也可以在创建标记生成器时设置它们。只需将它们列在一个字符串中即可。

数组列表是用于保存对象的可扩展容器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文