Java io: Create folder and print to text file from command : for example you this command where the second word is directory plus file name:
String fileName = "createF dir/text.txt";
String textToFile="apples, oranges";
How can I make "dir/text.txt" to make folder called dir and create a txtfile and write to it.

The issue is it is a command. And it is file name can be changed to another file name. I can't  use FileWriter method. It gives  no directory error.