Search code examples
javafilemaxline

Creating java File with unlimited number of lines


I am writing to file using java and I am writing more than 47678 lines. the maximum number of lines in the file is 47678. I am wondering if I can extend the number of the lines or what should I do. I am creating the file using File and I am writing using FileWriter


Solution

  • I don't see any problem with it e.g. the following program will write 65535 lines in the file:

    import java.io.*;
    class TestClass {
        public static void main(String args[]) throws IOException {
            BufferedWriter writer = new BufferedWriter(new FileWriter("test.txt"));
            for(int i=0;i<65535;i++)
                writer.write("Happy Diwali!\n");         
            writer.close(); 
        }
    }