编写一个程序,从文本文件中读取文本,然后全文打印字符后的字符,并在每个字符之间等待几秒钟

时间:2016-11-20 09:02:29

标签: java

我写的这个简单程序

从文本文件中读取文本 一切都很好,但是当我读大文时

该程序未读取所有文本

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);
        }

    }

}

我认为String变量无法保存大文本。那么解决这个问题的最佳方法是什么

我想阅读每个文本,无论多大

0 个答案:

没有答案
相关问题