Results 1 to 4 of 4
  1. #1
    aw249 is offline Member
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default Scanning a Plain text file

    Hey all,

    Ive encountered a dilema and unsure as to what the problem is, i have this piece of code that scans a text file and prints it....the problem is that it prints to the 269th line and then stops. This is the problem because the file has more than 1.4million lines.

    This is the current code that i have:
    import java.util.Scanner;
    import java.io.File;
    import java.io.FileNotFoundException;

    public class ScannerApp2 {

    public static void main(String[] args)
    {
    try
    {
    File file = new File("E:\\CO600\\misc\\movies.txt");
    Scanner scanner = new Scanner(file);
    while (scanner.hasNext())
    {
    System.out.println(scanner.nextLine());
    }
    scanner.close();
    }
    catch (FileNotFoundException e)
    {
    e.printStackTrace();
    }
    }
    }

    Please help because this is actually doing my head in.

    Many thanks

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default Re: Scanning a Plain text file

    Can you show us the content of that file around line #269? I suspect an en/decoding problem.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    aw249 is offline Member
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default Re: Scanning a Plain text file

    Hey thanks for the quick reply, this is the output:

    264 : "'Allo 'Allo!" (1982) {Flight of Fancy (#3.4)} 1986
    265 : "'Allo 'Allo!" (1982) {Forged Francs & Fishsellers (#5.15)} 1988
    266 : "'Allo 'Allo!" (1982) {Free at Last! (#7.2)} ????
    267 : "'Allo 'Allo!" (1982) {Good Staff Are Hard to Find (#4.3)} 1987
    268 : "'Allo 'Allo!" (1982) {Gruber Does Some Mincing (#3.2)} 1986
    269 : "'Allo 'Allo!" (1982)
    BUILD SUCCESSFUL (total time: 1 second)

    And this is how it is displayed in the the file itself, mind you the file is 91mb:

    "'Allo 'Allo!" (1982) {Good Staff Are Hard to Find (#4.3)} 1987
    "'Allo 'Allo!" (1982) {Gruber Does Some Mincing (#3.2)} 1986
    "'Allo 'Allo!" (1982) {Hans Goes Over the Top (#4.1)} 1987
    "'Allo 'Allo!" (1982) {Herr Flick's Revenge (#2.6)} 1985

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default Re: Scanning a Plain text file

    Can you (hex) dump around that line? Make sure there are no funny bytes on that line because the scanner has no reason to give up unless it reads a byte with a funny value,say, 0x1a or similar.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. plain text printing with java
    By berkeleybross in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2011, 01:01 AM
  2. Replies: 3
    Last Post: 06-08-2010, 08:10 PM
  3. Scanning text file and inserting contents into array
    By jmwalloh in forum New To Java
    Replies: 8
    Last Post: 03-24-2010, 12:33 PM
  4. Indentation - plain text
    By barney75 in forum New To Java
    Replies: 1
    Last Post: 03-23-2009, 05:54 PM
  5. convert html to plain text
    By vissu007 in forum New To Java
    Replies: 3
    Last Post: 07-07-2007, 02:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •