The best way to do it is:
String path = "C:" + File.separator + "hello" + File.separator + "hi.txt";
// Use relative path for Unix systems
File f = new File(path);
f.getParentFile().mkdirs();
f.createNewFile();
More Related Contents:
- Write byte array to file in java
- Writing object in text file
- How to move elements of Java ArrayList to file in java [closed]
- How to append text to an existing file in Java?
- How do I create a file and write to it?
- How do I create a Java string from the contents of a file?
- Scanner vs. BufferedReader
- How to read a specific line using the specific line number from a file in Java?
- Reliable File.renameTo() alternative on Windows?
- File Upload with Java (with progress bar)
- How to add a new line of text to an existing file in Java? [duplicate]
- Java IOException “Too many open files”
- Loading a text file into a textarea
- Writing a file to sdcard
- Java byte array contains negative numbers
- Java: CSV File Easy Read/Write
- How to delete a folder with files using Java
- Forward slash or backslash?
- Writing to console and text file
- Java scanner not going through entire file
- Why is using BufferedInputStream to read a file byte by byte faster than using FileInputStream?
- Read CSV file column by column
- Java read file and store text in an array
- Whole text file to a String in Java
- Random printing order for System.out & System.err calls [duplicate]
- Copy entire directory contents to another directory? [duplicate]
- Java OutOfMemoryError in reading a large text file
- Check if file exists without creating it
- Reading from a text file and storing in a String [duplicate]
- Difference between Files#delete(Path) and File#delete()