0

with the help of an expert here, i currently have the following:

File f = new File(inputFileName);
Scanner in = new Scanner(f);
String input = in.useDelimiter("\\Z").next();

However, if the file(all text inside) is too huge, my String object will only store from middle onwards till end of file? Any sugggestion? My that file size is around 3,000KB.

And also, how much char can a String store?So i know what file size and above will cuz my prog to crash

Thanks

Update: guys i realized the problem might not be my String is unable to store all the chars in the file but rather it is taking a very long time to process my compression hence. I am still debugging, will update as soon as i am very sure of the issue. Any guys know if substring will caused my prog to be very slow? As i dont thing there are any big issue with my algorithm

10e5x
  • 909
  • 4
  • 15
  • 27
  • have you tried tokenizer of split (storing it in array of strings)? – Xline Nov 16 '14 at 04:54
  • 1
    Why do you want to store all the chars of a very large file in a `String`? – Elliott Frisch Nov 16 '14 at 04:57
  • 1
    What is the actual task? – PM 77-1 Nov 16 '14 at 04:57
  • @ElliottFrisch @PM77-1 Although you want to help him, there is something fishy with this problem and addressing it should be prioritized, IMO, instead of coming up with an alternative or with a better approach. There are lots of questions involving 'large files' and `Scanner`, none explains why `Scanner` won't work with large files and they go with suggesting one of the buffered readers. – mostruash Nov 16 '14 at 05:19
  • @mostruash Which is why I asked why OP wants to do it. – Elliott Frisch Nov 16 '14 at 05:24
  • i am actually trying to compress a very large text file into a smaller text file using compression algorithm. – 10e5x Nov 16 '14 at 09:14

1 Answers1

0

First question has been answered here: Read large files in Java

Second question has partly been answered here: How many characters can a Java String have?

but exact answer is actually here: Do Java arrays have a maximum size?

Maximum # of char in String thus is:

Integer.MAX_VALUE - 5
Community
  • 1
  • 1
marcelv3612
  • 663
  • 4
  • 10