• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

Writing String to a txt file

Hi,
I am having a String which i m writing in a txt file using getBytes(), but if the contents of String are more then I am getting runtime error, may be due to limitation of byte array length. Please let me know how i can solve this problem.

Thanks,
R S
0
rajneetbhatia
Asked:
rajneetbhatia
  • 5
  • 3
  • 3
  • +3
2 Solutions
 
girionisCommented:
What error?
0
 
zzynxSoftware engineerCommented:
0
 
rajneetbhatiaAuthor Commented:
Writing to a file is ok, but the thing is my String contents may have lacs of lines. So I need to have a optimized code. I am planning to make a code which will get data in parts and enter that data into txt file in parts.

Thanks,
R S
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
girionisCommented:
You will probably need to look at the nio package: http://www-106.ibm.com/developerworks/edu/j-dw-java-nio-i.html
0
 
zzynxSoftware engineerCommented:
Sorry, rajneetbhatia I don't understand what you're trying to say
0
 
girionisCommented:
0
 
rajneetbhatiaAuthor Commented:
I will explain my problem in detail.

I am getting a data in String, which I am writing to a txt file. Code is working perfectly fine. But now I want to optimize the code for more data. i.e if String contains lacs of lines, even then data should be written in a txt file. In present case which I am trying, I am getting runtime error saying Data too large for try to handle. or byte error more size(if using getBytes()).

Please let me know how can I make a better code for large data.

(Writing into a file is not an issue, only the issue is for writing large data).

Thanks,
R S
0
 
rajneetbhatiaAuthor Commented:
I am getting the following error:---


Exception in thread "main" java.lang.ClassFormatError: FileOptDemo (Code of a me
thod longer than 65535 bytes)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
0
 
girionisCommented:
LOL how big is your method? Try to break it into smaller methods.
0
 
girionisCommented:
Or even smaller class files, since AFAIK there is a limit on how big class files can be (it will be fixed on jdk1.5).
0
 
zzynxSoftware engineerCommented:
>> Code of a method longer than 65535 bytes
That seems rather clear, isn't it?
As girionis says, break that huge method into smaller pieces.
0
 
primusmagestriCommented:
you can use refactoring if you cannot really decide where to break. just find some logic in your code and let refactoring assist you.
0
 
objectsCommented:
Sounds like you may have a long string constant in your code, if so I'd suggest moving the string out of the code and into a config file or similiar.
0
 
sciuriwareCommented:
I wrote a class that inevitably grew to 6000 lines and (only?) 45000 bytes of class file.
That's big, hu?

Now, you did not mention any dimension of what you wrote ....
From what you told us, I got the impression that it's not such a huge piece of code.
So it must be something else. Can you tell us some more?
;JOOP!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now