Results 1 to 7 of 7
Thread: BufferedWriter method: write
- 04-30-2012, 09:52 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 3
- Rep Power
- 0
BufferedWriter method: write
hello all(:
i'm trying to write something using file.write(String, int off, int len);
but when i enter the amount of characters in my string there is an error of exceeding count limit or something like that.
i was just wondering what the limit (highest number) is to use in int len to fix my code accordingly?
thanks!
- 04-30-2012, 09:54 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Re: BufferedWriter method: write
Posting your code as an SSCCE and all errors in their entirety does wonders to help yourself get help
- 05-01-2012, 02:59 AM #3
Member
- Join Date
- Apr 2012
- Posts
- 3
- Rep Power
- 0
Re: BufferedWriter method: write
sorry, i'm new to this.
okay so my code is:
finalFile.write(newRead,0,40);
where finalFile is the file i'm trying to write to and i want it to write string newRead which is about 40 characters long but when i run it the error says :
Error: String index out of range: 40
- 05-01-2012, 03:41 AM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Re: BufferedWriter method: write
See Short, Self Contained, Correct Example
Given what you posted I can guess (note: guesses can often be wrong) - your String is less than 40 characters long. Try passing in the len parameter of the method the actual length of the String you are writing.
- 05-01-2012, 04:45 AM #5
Member
- Join Date
- Apr 2012
- Posts
- 3
- Rep Power
- 0
Re: BufferedWriter method: write
thanks! let's see if this works now.
let's try again:
qqqint readLength = newRead.length(); //gets length of text
qqqqqtry{
qqqqqqqqFileWriter file = new FileWriter("out.txt");
qqqqqqqqBufferedWriter finalFile = new BufferedWriter(file);
qqqqqqqqfinalFile.write(newRead,0,readLength);
when i use this code it'll write part of the text (the last line of the three i have) even though i told it to write the length of the whole string...
- 05-01-2012, 07:53 AM #6
Re: BufferedWriter method: write
You've been asked twice to post a SSCCE, the second time with a link. If you can't be bothered to do that to help us help you, why should members here be bothered reading through uncompilable code snippets?
Also, as a new member you should have gone through the Forum Rules where you would have found a link to the Guide For New Members, and would have known how to post code here.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-01-2012, 10:22 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
How to Write to a File Using a Method
By Anagha in forum New To JavaReplies: 7Last Post: 04-06-2011, 06:50 AM -
Writing a method to write a method?
By balla in forum New To JavaReplies: 5Last Post: 04-01-2011, 12:05 PM -
BufferedWriter
By Karthika in forum New To JavaReplies: 6Last Post: 04-22-2010, 09:23 AM -
how to write method syntax ?
By Bader in forum New To JavaReplies: 2Last Post: 03-14-2010, 05:58 PM -
Trying to write toString method
By curious in forum New To JavaReplies: 3Last Post: 10-28-2009, 02:43 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks