Here is what I wanna do: 

1. Check if a folder exists
2. If it does not exists, create the folder
3. If it doest exists do nothing
4. At last create a file in that folder

Everything is working fine in Windows 7, but when I run the application in Ubuntu it doesn't create the folder, it is just creating the file with the folder name, example: (my file name is xxx.xml and the folder is d:\temp, so in Ubuntu the file is generated at d: with the name temp\xxx.xml). Here is my code:

```
File folder = new File("D:\\temp");
if (folder.exists() && folder.isDirectory()) {
} else {
    folder.mkdir();
}

String filePath = folder + File.separator;
File file = new File(filePath + "xxx.xml");

StreamResult result = new StreamResult(file);
transformer.transform(source, result);
// more code here 

```
['https://Stackoverflow.com/questions/20066413', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1966049/']
`D:\temp` does not exists in linux systems (what I mean is it interprets it as if it were any other foldername) 

In Linux systems the file seperator is `/` instead of `\` as in case of Windows 

so the solution is to : 

```
File folder = new File("/tmp"); 

```

instead of 

```
File folder = new File("D:\\temp");

```
Consider both solutions using the getProperty static method of System class.

```
String os = System.getProperty("os.name");

if(os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 || os.indexOf("aix") > 0 ) // Unix
    File folder = new File("/home/tmp"); 
else if(os.indexOf("win") >= 0) // Windows
    File folder = new File("D:\\temp");
else
    throw Exception("your message");

```