Using delimiter when reading a file

前端 未结 6 1031
执念已碎
执念已碎 2020-12-16 04:29

I have little experience using delimiters and i need to read a text file that stores several objects whose data is stored in single lines separate by commas (\",\"). The sep

6条回答
  •  生来不讨喜
    2020-12-16 04:45

    One issue is:

    while(read.hasNext())
       {
           title = read.nextLine();
           category = read.nextLine();
           runningTime = read.nextLine();
    
    hasNext()
    

    Returns true if this scanner has another token in its input. Not entire line. You need to use hasNextLine()

    You are doing nextLine() three times. I think what you need to do is, read the line and the split the line.

提交回复
热议问题