Is there an upper limit on .txt file size?

2019-04-18 15:04发布

As a Christmas gift I have written a small program in Java to calculate primes. My intention was to leave it on all night, calculating the next prime and writing it to a .txt file. In the morning I would kill the program and take the .txt file to my friend for Christmas.

Is there anything I should be worried about? Bear in mind that this is true beginner Ziggy you are talking to, not some smart error checking ASM guy.

EDIT More specifically, since I will be leaving this program on all night counting primes, is there any chance at all that I will encounter some kind of memory related error? Like, stacks crushing heaps or dogs and cats sleeping together?

EDIT even more specifically, is there a line of code I could put in to stop the printing of lines when the file's size is 4GB? Just to be safe?

EDIT: success: after leaving it on all night I got no more than 13 KB of primes, The highest I got was 22947217, which is like tens of thousands of primes. Success!

11条回答
别忘想泡老子
2楼-- · 2019-04-18 15:28

More than likely you are using an algorithm that is slow. As the primes get larger your program will be taking longer and longer to calculate a single prime. If you let it run over night the text file is not going to be very large in the morning. I'd be impressed if it's over a couple of megs.

查看更多
贪生不怕死
3楼-- · 2019-04-18 15:33

You might consider tracking the number of bytes you write to each file and switching to a new one after some number of bytes. You might also provide a viewer for your files so your friend can see his gift more easily. :)

查看更多
姐就是有狂的资本
4楼-- · 2019-04-18 15:34

Technically, there is no limit except that which the file system places on you. However, Notepad is really cranky about opening obscenely large files.

查看更多
何必那么认真
5楼-- · 2019-04-18 15:34

How about saving some CPU cycles and just downloading a pre-computed list of primes? Or is it more "the thought that counts"? :)

查看更多
时光不老,我们不散
6楼-- · 2019-04-18 15:34

What about just creating one file for each prime number and then use the filename to display the number?

查看更多
登录 后发表回答