0

This simple program I wrote

To read the text from a text file Everything is fine, but when I read large text

The program does not read all the text

public class Testing {

    public static void main(String[] args) throws InterruptedException {

        System.out.print("Enter the path \".txt\" :");

        Scanner inputPath = new Scanner(System.in);

        String path =inputPath.nextLine();  
        System.out.print("Enter the speed of printing fromm (100-10000) :");
        int speed=inputPath.nextInt();

        try{
            FileReader file = new FileReader(path);

            String data = new Scanner(file).useDelimiter("\\z").next();

            for(int i=0;i<data.length();i++){

                System.out.print(String.valueOf(data.charAt(i)));
                Thread.sleep(speed);
            }

        } //methode for save file path inside program
        catch(FileNotFoundException x) {
            JOptionPane.showMessageDialog(null, x);
        }

    }

}

I think the String variable can not save a large text. so what is the best way to solve this problem

I want to Read each text no matter how big

Vojtech Ruzicka
  • 16,384
  • 15
  • 63
  • 66
user326260
  • 45
  • 5
  • Is your actual question whether or not `String` can hold your entire file's text, or does the code logic above in fact not do what you need? – errantlinguist Nov 20 '16 at 09:06
  • Possible duplicate of [How do I create a Java string from the contents of a file?](http://stackoverflow.com/questions/326390/how-do-i-create-a-java-string-from-the-contents-of-a-file) – errantlinguist Nov 20 '16 at 09:07
  • What makes you think that this code doesn't work the way you want? Please add problem description, not only code requirements. – Pshemo Nov 20 '16 at 09:10
  • "Everything is fine, but when I read large text The program does not read all the text" is a bit vague. What do you mean by large text? How exactly big it is, which part is read and which is skipped? – Pshemo Nov 20 '16 at 09:12
  • The text about 600 lines the program just read 100 line – user326260 Nov 20 '16 at 09:20
  • Looks like bug http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8028387 found in similar question: [Behavior of using \Z vs \z as Scanner delimiter](https://stackoverflow.com/questions/22350037/behavior-of-using-z-vs-z-as-scanner-delimiter) – Pshemo Nov 20 '16 at 09:35
  • Try with `.useDelimiter("\\A").next();` instead of `.useDelimiter("\\z").next();`. – Pshemo Nov 20 '16 at 09:37

0 Answers0