4

I currently comprise the following code which fails to compile. The else if statement reports that ';' expected. I don't understand why I can't use a else if for this scenario?

public class FileConfiguration {

    private String checkOs() {
        String path = "";        
        if (System.getProperty("os.name").startsWith("Windows")) {
            // includes: Windows 2000,  Windows 95, Windows 98, Windows NT, Windows Vista, Windows XP
            path = "C://Users//...";            

        }
        elseif (System.getProperty("os.name").startsWith("Mac")) {
            path = "///Users//...";
        }
        return path;        

    }

    // declare paths for file source and destination 
    String destinationPath = path;
    String sourcePath = path;
Cœur
  • 37,241
  • 25
  • 195
  • 267
keenProgrammer
  • 438
  • 2
  • 10

3 Answers3

7

It would be better if you were to use user.name and user.home. You can also get the separator using file.separator. Check this out. Those properties will really help you do this more cleanly without checking the OS.

Then there's also the matter of you needing to change to using else if, not elseif...

Mike Thomsen
  • 36,828
  • 10
  • 60
  • 83
2

elseif does not exist in java. You must use else if as:

if (a) {
// code
} else if (b) {
// code
}
bigjocker
  • 53
  • 1
  • 5
1

There is no elseif keyword in java. You should say else if (pay attention on the space)

AlexR
  • 114,158
  • 16
  • 130
  • 208