へのファイル書き込みを作成します。

File file1 = null;
	if (!file.isFile()) {
		file1 = new File("E:\\a\\aa\\b\\test.txt");
		boolean createNewFile = false;
		try {
			createNewFile = file1.createNewFile();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(createNewFile);
	}
	String str = "这些都将写入文件中";
	byte[] bb = str.getBytes(); // 将字符串转换成字节数
	OutputStream out = null;
	try {
		out = new FileOutputStream(file1); // 实例化OutpurStream
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}
	// 写入
	try {
		out.write(bb); // 写入
		out.close(); // 关闭
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	System.out.println("----------------------------------------");
公開された14元の記事 ウォンの賞賛1 ビュー237

おすすめ

転載: blog.csdn.net/weixin_45061669/article/details/104830122