I have a following code in test
public class TestMe {
private static final String BACKUP_DIR_PATH = "~/backup";
@Test
public static void createBackupDir() throws IOException {
File path = new File(BACKUP_DIR_PATH + "/" + getFolderName()).getCanonicalFile();
System.out.println(path.mkdirs());
}
// returns 2012-07-23
private static String getFolderName() {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
return dateFormat.format(date).toString();
}
}
When I run this test it returns false
Both backup and 2012-07-23 folder does not exists
What is incorrect here?
It’s probably because Java doesn’t know what the
~means.The
~is a shell expansion, not a valid pathname.