K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
TSang wrote:
once the data is read into a byte array, try using new String (byte[], "UTF-8").
My Comments : i want the ?(question mark) to be removed in the bufferedReader object and again i need to return the bufferedReader object ONLY. I have googled enough and did not find any help..
return type should be bufferedReader object without the ?(question mark)
Please suggest on how to proceed....
i want the ?(question mark) to be removed in the bufferedReader object and again i need to return the bufferedReder object. I have googled enough and did not find any help..
return type should be bufferedReader object and without the ?
The first 3 are illegal i need to remove them and assign it back to bufferedReader object ... please advice....
I have tried the below,could you help me further please.....
Henry Wong wrote:
Just thought of something -- if the illegal characters are always in the beginning, then one other option would be to read off the characters before returning the BufferedReader...
Henry
henry wrote:
Just thought of something -- if the illegal characters are always in the beginning, then one other option would be to read off the characters before returning the BufferedReader...
Deepak Lal wrote:
but do i accomplish it....please need help on this henry.... you are saying read off the characters but i dont know how to accomplish it....can you tell me which api supports reading off the first 3 bytes and then return it back to bufferedReader....
Please advice on this now. I did as [you] suggested...what is wrong now....
Henry Wrote :
Take a look at the BufferedReader methods -- particularly the read(), mark(), and reset() methods.
Basically, mark() the beginning of the file, then read() the first three characters (not a line, just the first three characters). If the first three characters are junk characters, then you are done. Simply return the BufferedReader back from the method. If the first three characters are not junk characters, then reset() the buffered reader, and then return it back from the method.
Anyone who uses the returned BufferedReader will not get the junk characters, when they try to read from it (as you already taken it off from the stream).
Even the code in my previous post is doing the same steps.( as you have suggested)(junk character is @ beginning of file)
mark() the beginning of the file,
then read() the first three characters
(not a line, just the first three characters).
If the first three characters are junk characters, then you are done. Simply return the BufferedReader back from the method. If the first three characters are not junk characters, then reset() the buffered reader, and then return it back from the method.
mark
public void mark(int readAheadLimit)
throws IOException
Marks the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point.
Overrides:
mark in class Reader
Parameters:
readAheadLimit - Limit on the number of characters that may be read while still preserving the mark. An attempt to reset the stream after reading characters up to this limit or beyond may fail. A limit value larger than the size of the input buffer will cause a new buffer to be allocated whose size is no smaller than limit. Therefore large values should be used with care.
Throws:
IllegalArgumentException - If readAheadLimit is < 0
IOException - If an I/O error occurs
BufferedReader Api says:
read
public int read()
throws IOException
Reads a single character.
Overrides:
read in class Reader
Returns:
The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
bufferedReader.mark(0) ; //Marks the present position in the stream hence i have marked as Zero. now what is wrong with this statement.
Next Step: Since there is only one junk character,im reading a single character
int k = bufferedReader.read(); // Reads a single character. hence im reading a single character see api below
System.out.println("k is "+k); //here k is displaying the value as 49 which is charValue(1) which is not a junk character but we see line is having a junk character.
Please tell me where i have gone wrong now....
K. Tsang wrote:Hello Deepak, having looking through your posts in detail. Have you consider your way of approach using RandomAccessFile readUTF() method. I think this may make life easier. Rather than BufferReader stuff.
Deepak Lal wrote: Please what parameter should i pass to my mark method in this scenario...could you correct that and i will proceed further...
Im confused.![]()
![]()
Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Deepak Lal wrote:Hi Henry,
Could you please paste the code which could help me to achieve the impossible.i have been struggling to get ghis done....please
As a side note, of all the suggestions so far, I still like the first one the best -- writing a FilteredReader that can wrapped by the Buffered reader (that removes all the illegal chars automatically). It's definitely the most elegant, IMHO.
You have to make sure that this number is large enough, or you won't be able to reset. In your example, you need to have enough room to hold the line you are reading and will later reset.
this number is large enough. can you atleast tell me large enough means what could be the value.
example if there are 300 lines,then approximately
1001528770;PHP;ABQ;PHP;22;SHA;123456789;Tan Ya Ling;26:11:2008;07
1001528770;PHP;ABQ;PHP;22;SHA;123456789;Tan Ya Ling;26:11:2008;07
1001528770;PHP;ABQ;PHP;22;SHA;123456789;Tan Ya Ling;26:11:2008;07
1001528770;PHP;ABQ;PHP;22;SHA;123456789;Tan Ya Ling;26:11:2008;07
upto 300 lines.
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
|