converting file data to string
-
Hello Friends I am reading a file Like this here is the code below:
FileInputStream in = new FileInputStream(file); Reader r = new InputStreamReader(in, "ISO-8859-1"); int intch; while ((intch = r.read()) != -1) { int temp = intch; }
Previously I was putting all data into another file char by char like this
OutputStream out = new FileOutputStream(outFilePath);
and using out.write(temp); in while loopAnd it was working fine. But now The value coming in temp ,I want to store in a string.temp contains some int value of that charset and I want tht in string. Any Suggestions?? Thanks In Advance. Regards Yogesh
-
Hello Friends I am reading a file Like this here is the code below:
FileInputStream in = new FileInputStream(file); Reader r = new InputStreamReader(in, "ISO-8859-1"); int intch; while ((intch = r.read()) != -1) { int temp = intch; }
Previously I was putting all data into another file char by char like this
OutputStream out = new FileOutputStream(outFilePath);
and using out.write(temp); in while loopAnd it was working fine. But now The value coming in temp ,I want to store in a string.temp contains some int value of that charset and I want tht in string. Any Suggestions?? Thanks In Advance. Regards Yogesh
Or Is there any way to read file line by line thru BufferedReader whose data is in ISO-8859-1 charset. I tried like this even
this(new BufferedReader(new InputStreamReader(new FileInputStream(file),"ISO-8859-1")));
but bufferedReader is coming null. Any Ideas?? Regards Yogesh
-
Or Is there any way to read file line by line thru BufferedReader whose data is in ISO-8859-1 charset. I tried like this even
this(new BufferedReader(new InputStreamReader(new FileInputStream(file),"ISO-8859-1")));
but bufferedReader is coming null. Any Ideas?? Regards Yogesh
I'm kind of new to this whole Java thing but there is a readLine() method on BufferedReader. How about something like this? ISO-8859 is a standard 8 bit character encoding so you shouldn't have problems reading the file.
String line; BufferedReader br = new BufferedReader(new FileReader(fileName)); while ((line = br.readLine()) != null) { // do stuff with line } br.close();
-
I'm kind of new to this whole Java thing but there is a readLine() method on BufferedReader. How about something like this? ISO-8859 is a standard 8 bit character encoding so you shouldn't have problems reading the file.
String line; BufferedReader br = new BufferedReader(new FileReader(fileName)); while ((line = br.readLine()) != null) { // do stuff with line } br.close();
-
I already Tried like this but bufferedReader is coming null. And moreover it would be better if somebody suggest how can I convert each ISO-8859-1 character into String Bcoz I have to do some decoding for each character. Thanks Yogesh
What do you mean "bufferedReader is coming null"? If I do this:
BufferedReader br = new BufferedReader(new FileReader(fileName));
then either I will get a BufferedReader created or I will get a FileNotFoundException. I can't quite see how you are getting a null here. If file encoding is a problem for you then use InputStreamReader: http://java.sun.com/docs/books/tutorial/i18n/text/stream.html[^]
-
What do you mean "bufferedReader is coming null"? If I do this:
BufferedReader br = new BufferedReader(new FileReader(fileName));
then either I will get a BufferedReader created or I will get a FileNotFoundException. I can't quite see how you are getting a null here. If file encoding is a problem for you then use InputStreamReader: http://java.sun.com/docs/books/tutorial/i18n/text/stream.html[^]