简体   繁体   English

读取文件然后存储在数组中而不使用arraylist java

[英]Read file then store in array without using arraylist java

I am trying to read a file with 8 columns of data and store each string of data into an array, but I keep getting cannot find symbol error for employee.length. 我正在尝试读取具有8列数据的文件并将每个数据字符串存储到一个数组中,但是我一直无法找到employee.length的符号错误。 I put 8 elements for each string within the row. 我在行中为每个字符串放置了8个元素。 Please help me by explaining what I am doing wrong. 请通过解释我做错了什么来帮助我。 Code: 码:

Scanner scan = new Scanner(new FileReader ("payrollData.dat")); 扫描仪扫描=新扫描仪(新FileReader(“ payrollData.dat”));

    String employee[] = new String[8];

    while(scan.hasNext())
    {   
        for(int i = 0; i < employee.length(); i++)
        {
            employee[i] = scan.next();
        }
    }

    System.out.println(employee);8

Its employee.length and not employee.length() . 它的employee.length而不是employee.length() In case of arrays, length is a final variable, not a method. 对于数组,length是最终变量,而不是方法。

And use Arrays.toString(employee) to print employees properly. 并使用Arrays.toString(employee)正确打印员工。 System.out.println(employee) will just print the reference address. System.out.println(employee)只会打印参考地址。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将文件读取到Array,然后将Array存储到ArrayList Java中 - Read file to Array then store Array into ArrayList Java 如何读入 txt 文件的 1 个特定列并将其存储到 Array 或 ArrayList [Java] - How to read in 1 specific column of a txt file and store into an Array or ArrayList [Java] Java读取arraylist中的特定文件存储 - Java read specific file store in arraylist Java-读取文本文件,将内容存储在ArrayList中,打印ArrayList - Java - Read Text File, Store Contents in ArrayList, Print ArrayList 转换 ArrayList<string> 带引号从外部 txt 文件读取到 ArrayList<string> 没有引号使用 Java 8</string></string> - Convert ArrayList<String> With Quotes Read from an external txt file to ArrayList<String> Without the Quotes Using Java 8 Java - 使用扫描仪读取文本文件并存储它,给我空的 ArrayList。 使用分隔符拆分单词 - Java - Read text file and store it using scanner, gives me empty ArrayList. Split words by using Delimeter 如何通过(选项卡)读取 csv 文件并通过 java 将文件存储到 arraylist - how to read csv file by (tab) and store file to arraylist by java java:读取文本文件并使用scanner类将信息存储在数组中 - java: Read text file and store the info in an array using scanner class 在数组列表中输入数据而不在Java中使用数组 - input data in an arraylist without using an array in java Java I / O读取多行文件并存储为arraylist - java i/o read in multi line file and store as arraylist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM