473,387 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

string out to file

hello one and all,

i am still new to java but becoming ever so more efficient. i need some
advice and guidance on big strings. i am debugging a special counter
that i created in java and i am iterating to check the count sequence.
i am then outputting the sequence to a jTextPane. however, the
iterations are too large for the jTextPane object and i get an "out of
memory" error while debugging.

so i can output to a file. what is the best way to output short
strings, 3 to 4 characters long followed by a line feed. there may be
700,000 lines or more in the file when done. so what is the best way to
write to an ascii text file in java?

thanx in advance.

lucas

Jul 17 '05 #1
2 9215
> so what is the best way to
write to an ascii text file in java?


Check the API documentation for FileOutputStream and BufferedWriter.
These are classes that you may need to accomplish your tasks.

Create a FileOutputStream and specify the filename and path in its
constructor, then create the BufferedWriter (for enhanced performance)
specifying the FileOutputStream in its constructor. There may be some
examples on the Internet on how to use BufferedWriter.

Note that 700K lines of 5 characters each (newline counts as a
character) will be not much of a problem, unless you try to open it in
Micro$oft's NotePad.

Regards,

Joost
Jul 17 '05 #2
yes, that worked quite well, and it was fast without filling up the RAM.

this is what i ended up with:

try {
BufferedWriter oBuffer = new BufferedWriter(new OutputStreamWriter(new
FileOutputStream("/home/lucas/inc_chr_java.txt"),"UTF8"));
int ll = 4/*jTextField1.getText()*/;
String cc = iqs.padl("",ll);
String ee = iqs.padlchr("",'~',ll);
do {
cc = iqs.incChr(cc,ll);
oBuffer.write(cc); oBuffer.newLine();
}
while (!cc.equals(ee));
oBuffer.flush(); oBuffer.close();
}
catch (IOException except) {
return;
}

thanx again for the help.

lucas
remove .nospam wrote:
so what is the best way to write to an ascii text file in java?

Check the API documentation for FileOutputStream and BufferedWriter.
These are classes that you may need to accomplish your tasks.

Create a FileOutputStream and specify the filename and path in its
constructor, then create the BufferedWriter (for enhanced performance)
specifying the FileOutputStream in its constructor. There may be some
examples on the Internet on how to use BufferedWriter.

Note that 700K lines of 5 characters each (newline counts as a
character) will be not much of a problem, unless you try to open it in
Micro$oft's NotePad.

Regards,

Joost


Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Senthoorkumaran Punniamoorthy | last post by:
I am printing these information. print string.lower(info_res) print string.lower(md5sum(f_md5)) print len(string.lower(info_res)) print len(string.lower(md5sum(f_md5))) print...
2
by: zjut | last post by:
want to add a string to the file and the file is sort by letter! for examply: the follow file is a big file! ////////////////////// abort black cabbage dog egg fly ////////////////////
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
22
by: Jason Heyes | last post by:
Does this function need to call eof after the while-loop to be correct? bool read_file(std::string name, std::string &s) { std::ifstream in(name.c_str()); if (!in.is_open()) return false; ...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
14
by: Josh Baltzell | last post by:
I am having a lot more trouble with this than I thought I would. Here is what I want to do in pseudocode. Open c:\some.pdf Replace "Replace this" with "Replaced!" Save c:\some_edited.pdf I...
7
by: Malcolm | last post by:
This is a program to convert a text file to a C string. It is offered as a service to the comp.lang.c community. Originally I thought it would be a five minute job to program. In fact there are...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
2
by: laksh2007 | last post by:
i want to search and replace strings present in a file (entire file).. i have wirtten cod eto do this.. but it is not working as expected.. code is : import java.io.*; import java.util.*;
11
by: blunt | last post by:
trying to write a program to write the configuration files for a load of wireless access points. i've never been a good programmer and haven't done any for nearly a decade so have obviously made some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.