0

I would like to know the maximum size of data that a JTextPane could hold. This is needed as I am unable to retrieve the entire contents of a JTextPane , for writing out to a file , in an application at my office.

In that application I generate XML based on some business logic , load it into a JTextPane and upon validation of the same , write it out to the disk.

I'm losing a part of the JTextPane contents ( the data that is to be written out) on creating a File object for this purpose.

Aditya Kaushik
  • 213
  • 1
  • 4
  • 20
  • 1
    Could you be more specific? What kind of limits are you looking for? Why does it matter to you? – Guillaume Polet Jun 19 '13 at 10:23
  • 1
    Do you mean before you run out of memory, or before its performance becomes unusable to an end-user ? And have you already tried adding heaps of text to it ? – Robin Jun 19 '13 at 10:23
  • @GuillaumePolet I wish to save the contents of a JTextPane to a file. But I am unable to save the entire file , only a small section of it. Thats why the question. – Aditya Kaushik Jun 19 '13 at 10:27
  • @Robin The MAXIMUM number of characters I can retrieve from a JTextPane at any time using the getText() method. – Aditya Kaushik Jun 19 '13 at 10:28
  • @Abe Then your question should probably be about how to save textpane content to a file. In that case, consider providing an [SSCCE](http://sscce.org) illustrating what you have done so far. – Guillaume Polet Jun 19 '13 at 10:29
  • 1
    Consider using the `write()` method iso using `getText()` for writing to file. And note that your question very poorly reflects what you actually try to achieve and where you encounter problems. Consider updating it – Robin Jun 19 '13 at 10:35
  • _But I am unable to save the entire file , only a small section of it._ Most likely you are doing something wrong and it is unlikely a question of limits. – Guillaume Polet Jun 19 '13 at 10:39
  • *"..how much data can a JTextPane hold at one time ?"* More than a user can handle or even effectively navigate. Easily the Old Testament (yes, all of it), for e.g. – Andrew Thompson Jun 19 '13 at 14:54

1 Answers1

0

You'll probably be retrieving the contents of the JTextPane as a String at some point which means that you'll have a technical upper limit of just over 2 billion characters (as discussed here). Having said that the application will become totally unresponsive long before you get anywhere close to that number of characters.

As for saving the contents to a file you shouldn't have any problems writing out that much data assuming you have a couple of GB of free disk space. If you need an example of writing a file have a look here.

It is possible that you are losing the end of the data because you aren't closing the stream when you are finished with it or you are using a buffer and failing to flush it correctly after the last write.

Community
  • 1
  • 1
wobblycogs
  • 4,083
  • 7
  • 37
  • 48