[Java] Create File with java.io.File class
Create a file with some content in some specific location. The reference is here.
/**
* Write fileContent in a file and save it into FileToCreatePath
*
* @param fileContent content of the file
* @param FileToCreatePath path of the file been saved
* @throws IOException
*/
private static void createFile(String fileContent, Path FileToCreatePath) throws IOException
{
File file = FileToCreatePath.toFile();
if (file.createNewFile())
{
System.out.println(FileToCreatePath.toString() + " is created!");
}
else
{
System.out.println(FileToCreatePath.toString() + " already exists.");
}
FileWriter writer = new FileWriter(file);
writer.write(fileContent);
writer.close();
}
E.g if want to create a HelloWorld.txt file, then we just need to use
static final String _txtContent = "Hello World!!!";
static final Path _FilePath = Paths.get(
System.getenv("APPDATA"),
"HelloWorld.txt"
); // if we want to create different file , like .java, .py or .vbs, we just need to change the name in the _FilePath. createFile(_txtContent, _FilePath);
[Java] Create File with java.io.File class的更多相关文章
- Java ——扩展:内部类 匿名内部类 IO file 设计模式
内部类的拓展 定义类or方法内部的类 最外层的类只能使用public和默认修饰 class Demo { class A { } public static void main(String[] ar ...
- java获取指定路径下的指定文件/java.io.File.listFiles(FilenameFilter filter)
java.io.File.listFiles(FilenameFilter filter) 返回抽象路径名数组,表示在目录中此抽象路径名表示,满足指定过滤器的文件和目录. 声明 以下是java.io. ...
- java.io.NotSerializableException: test.io.file.Student
java.io.NotSerializableException: test.io.file.Student at java.io.ObjectOutputStream.writeObject0 ...
- IO:File类(java.io.File)
public class File extends Object implements Serializable, Comparable<File> 构造方法: public File(S ...
- java.io.file
package cn.edu.tongji.cims.wade.system; import java.io.*; public class FileOperate { pub ...
- 【java IO File】统计项目代码总共多少行
统计项目代码总共有多少行 思想: 1.首先将不需要迭代的文件夹,保存在集合中,不满足的就是需要迭代的文件夹 2.将需要进行统计行数的代码文件保存在集合中,满足的就是需要计算文件行数的文件 3.迭代方法 ...
- java.io.File类
java.io.File类 1.凡是与输入.输出相关的类.接口等都定义在java.io包下 2.File是一个类.能够有构造器创建其对象.此对象相应着一个文件(.txt .avi .doc .ppt ...
- Java基础知识强化之IO流笔记10:File类输出指定目录下指定后缀名的文件名称案例(File类的文件过滤器方法改进list( FilenameFilter ff))
1. 案例: 判断F盘下是否有后缀名为.jpg的文件,如果有的话,就输出这个文件名. 2. 案例代码如下: (1)思路是:先获取所有的文件和文件夹封装的对象,然后遍历的时候,依次判断,如果满足条件就输 ...
- 详谈JAVA中的file类与IO流
File类 位置于java.io包构造方法:File(String parent, String child)new file("d:\\","a.txt") ...
随机推荐
- Flask web开发之路四
jinjia2模板 模板渲染和参数传递 项目结构如下: 主app文件代码: from flask import Flask,render_template app = Flask(__name__) ...
- triangular distribution
mode(众数), 一组数据中出现次数最多的那个(或那些)数值. 众数可以不存在或多于一个. 例如, 1,2,3,3,4的众数是3. 1,2,2,3,3,4的众数是2和3. 1,2,3,4,5没有众数 ...
- content-type对照表
- 蓝桥杯 入门训练 Fibonacci数列 解析
问题描述 Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1. 当n比较大时,Fn也非常大,现在我们想知道,Fn除以10007的余数是多少. 输入格式 输入包含一个整数n ...
- Codeforces 1137D - Cooperative Game - [交互题+思维题]
题目链接:https://codeforces.com/contest/1137/problem/D 题意: 交互题. 给定如下一个有向图: 现在十个人各有一枚棋子(编号 $0 \sim 9$),在不 ...
- python与pycharm安装
1.python install 1.1 下载安装包 - https://www.python.org/downloads 1.2 installl 1.2.1 双击exe安装文件 1.3 如果安装 ...
- 一个列转行SQL示例(wm_concat函数和replace函数合用)
准备测试数据: create table test01( groupid number, a number, b number, c ...
- wfp(Application的运用)
1.Application中封装了wpf的一些常用的功能,如检查未经处理的异常,处理命令行参数等. 2.如何启动wpf程序: app.xaml可用于启动wpf的窗体.也可以不用这用方式.直接创建一个a ...
- [https][ssl] keyless SSL
HTTP Server 集群前的负载设备,或内容审计设备等,在处理https的时候,需要用户配置提供证书. 但是考虑到安全问题,HTTP Server并不愿意把证书配置到其他设备上. 这个时候,就有个 ...
- H2O 笔记之安装
参考资料: 了解H2O:http://h2o-release.s3.amazonaws.com/h2o/rel-turchin/9/docs-website/h2o-docs/index.html 安 ...