Link to home
Start Free TrialLog in
Avatar of MidhunKumar
MidhunKumar

asked on

unsetf(ios::skipws) equivalent in java

I am porting the code from c++ to java. I want to replace the statement unsetf(ios::skipws) in java.

unsetf(ios::skipws) --> means that whitespaces should not be skipped while reading from a stream.

Example :
public static void main (String a)
{
char ch;
while(1){
ch=  readCharFromFile(); // usually the spaces will be skipped while reading a character
                                         // but i want to read even the spaces
System.out.println( ch);
}
}
public static void main (String a)
{
char ch;
while(1){
ch=  readCharFromFile(); // usually the spaces will be skipped while reading a character
                                         // but i want to read even the spaces 
System.out.println( ch);
}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Any further questions on whitespace?
that option does not exist in Java
What you need to be aware of though is that you should use a Reader for reading charactere data instead of a InputStream to ensure character encoding is handled correctly

some good background here
http://java.sun.com/docs/books/tutorial/essential/io/charstreams.html
for doing things like skipping whitespace you would use something like a Scanner
You would use a FilterReader for skipping whitespace (not that you want to)
Avatar of MidhunKumar
MidhunKumar

ASKER

Actually i dont want to skip the whitespace.
CEHJ:

Are you sure that java wont skip the whitespaces? Do you confirm that i wont need statements like unsetf ?
No a standard Reader will not skip whitespace.
>>Actually i dont want to skip the whitespace.
CEHJ:

Are you sure that java wont skip the whitespaces?

Certain ;-) As i said at http:#24878838
:-)