you can do something of this sort:
file.getParentFile().mkdirs();
Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.
Update
if (file.getParentFile().exists || file.getParentFile().mkdirs()){
try
{
file.createNewFile();
}
catch(IOException ioe)
{
ioe.printStackTrace();
return;
}
} else {
/** could not create directory and|or all|some nonexistent parent directories **/
}