aspose file tools*
The moose likes Beginning Java and the fly likes ? about cross platform compatibility Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "? about cross platform compatibility" Watch "? about cross platform compatibility" New topic
Author

? about cross platform compatibility

Paul LaBrier
Greenhorn

Joined: Apr 08, 2002
Posts: 21
In order to get th output of a console app to pause and keep the results from scrolling off the screen I did the following.
public static void main(String args[])
throws java.io.IOException
{
exercise7dot8a();
System.out.print("\n\nPress ENTER to continue:");
System.in.read();
exercise7dot8b();
System.out.print("\n\nPress ENTER to continue:");
System.in.read();
exercise7dot8c();
System.out.print("\n\nPress ENTER to continue:");
System.in.read();
exercise7dot8d();
System.out.print("\n\nPress ENTER to continue:");
System.in.read();
exercise7dot8e();
}
[/CODE]
When I compiled and executed it on a Sun Sparc20 running Solaris 7 it worked fine. When I tried it on Win98se it would only pause the first and third time. It would skip the second and fourth time. I recompiled it on Win98se and no change.
Does anyone have any ideas what causes this?
Paul LaBrier
Snigdha Solanki
Ranch Hand

Joined: Sep 07, 2000
Posts: 128
The reason for this behaviour is because of different ways OS interprets "Enter" key. On Unix, it is <LF> (Line Feed); on DOS, it is <CR>+<LF>(Carriage Return + Line Feed) and on Macintosh, it is <CR>.
Check out the below program. It should work on both Windows and Unix though I have not tested it.

where 10 is the Ascii value of LF.


Snigdha<br />Sun Certified Programmer for the Java™ 2 Platform
Paul LaBrier
Greenhorn

Joined: Apr 08, 2002
Posts: 21
Thank you for that explaination. That makes perfect sense. I should have thought of that.
Paul LaBrier
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Of course the example wouldn't work on Mac, so it isn't really platform independent.
The following, OTOH, should work everywhere:


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
Consider Paul's rocket mass heater.
 
subject: ? about cross platform compatibility