练习 - 写入数据到文件
如果是写入数据到d:/xyz/lol2.txt,而目录xyz又不存在的话,就会抛出异常。
那么怎么自动创建xyz目录?
public static void main(String[] args) {try {File f = new File("f:/lolfolder2/lol2.txt");if (!f.getParentFile().exists()){f.getParentFile().mkdirs();f.createNewFile();}FileOutputStream fos = new FileOutputStream(f);fos.write(69);fos.close();}catch (IOException e){e.printStackTrace();}}
