unsetf(ios::skipws) equivalent in java

MidhunKumar
MidhunKumar used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
Whitespace is never skipped anyway - so no problem
Top Expert 2016

Commented:
Any further questions on whitespace?
Mick BarryJava Developer
Top Expert 2010

Commented:
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
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Mick BarryJava Developer
Top Expert 2010

Commented:
for doing things like skipping whitespace you would use something like a Scanner
Top Expert 2016

Commented:
You would use a FilterReader for skipping whitespace (not that you want to)

Author

Commented:
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 ?
Mick BarryJava Developer
Top Expert 2010

Commented:
No a standard Reader will not skip whitespace.
Top Expert 2016

Commented:
>>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
Top Expert 2016

Commented:
:-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial