Solved

Writing String to a txt file

Posted on 2004-09-02
16
224 Views
Last Modified: 2010-03-31
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
Comment
Question by:rajneetbhatia
  • 5
  • 3
  • 3
  • +3
16 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11963099
What error?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 11963101
0
 

Author Comment

by:rajneetbhatia
ID: 11963155
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
 
LVL 35

Expert Comment

by:girionis
ID: 11963171
You will probably need to look at the nio package: http://www-106.ibm.com/developerworks/edu/j-dw-java-nio-i.html
0
 
LVL 37

Expert Comment

by:zzynx
ID: 11963194
Sorry, rajneetbhatia I don't understand what you're trying to say
0
 
LVL 35

Expert Comment

by:girionis
ID: 11963199
0
 

Author Comment

by:rajneetbhatia
ID: 11963295
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:rajneetbhatia
ID: 11963312
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
 
LVL 35

Accepted Solution

by:
girionis earned 25 total points
ID: 11963322
LOL how big is your method? Try to break it into smaller methods.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11963347
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
 
LVL 37

Expert Comment

by:zzynx
ID: 11963356
>> 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
 
LVL 1

Expert Comment

by:primusmagestri
ID: 11963623
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
 
LVL 92

Assisted Solution

by:objects
objects earned 25 total points
ID: 11968982
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 11981062
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now