在Java中创建文件的方式有以下几种:
File file = new File("example.txt");
file.createNewFile();
FileOutputStream fos = new FileOutputStream("example.txt");
// 写入数据到文件
fos.write("Hello, world!".getBytes());
fos.close();
BufferedWriter writer = new BufferedWriter(new FileWriter("example.txt"));
writer.write("Hello, world!");
writer.close();
String content = "Hello, world!";
Files.write(Paths.get("example.txt"), content.getBytes());
RandomAccessFile raf = new RandomAccessFile("example.txt", "rw");
raf.writeBytes("Hello, world!");
raf.close();