用当前日期生成一个文件
2007-05-15 15:06
513 查看
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class FileTest {
public static void main(String[] args) {
a.createFile("c:","this is a testfile!");
}
/**
* 新建文件
* @param filePathAndName 文本文件完整绝对路径及文件名
* @param fileContent 文本文件内容
* @return
*/
public static void createFile(String filePath,String fileContent) {
try {
//组成文件名
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String dateFileName = formatter.format(new Date());
String path = filePath+"//group1_log_"+dateFileName+".txt";
filePath = filePath.toString();
File myFilePath = new File(path);
if (!myFilePath.exists()) {
myFilePath.createNewFile();
}
FileWriter resultFile = new FileWriter(myFilePath);
PrintWriter myFile = new PrintWriter(resultFile);
String strContent = fileContent;
myFile.println(strContent);
myFile.close();
resultFile.close();
System.out.println("create file ok!");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
public class FileTest {
public static void main(String[] args) {
a.createFile("c:","this is a testfile!");
}
/**
* 新建文件
* @param filePathAndName 文本文件完整绝对路径及文件名
* @param fileContent 文本文件内容
* @return
*/
public static void createFile(String filePath,String fileContent) {
try {
//组成文件名
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String dateFileName = formatter.format(new Date());
String path = filePath+"//group1_log_"+dateFileName+".txt";
filePath = filePath.toString();
File myFilePath = new File(path);
if (!myFilePath.exists()) {
myFilePath.createNewFile();
}
FileWriter resultFile = new FileWriter(myFilePath);
PrintWriter myFile = new PrintWriter(resultFile);
String strContent = fileContent;
myFile.println(strContent);
myFile.close();
resultFile.close();
System.out.println("create file ok!");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
相关文章推荐
- 未能加载文件或程序集“xxx”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集
- 写一个通用的copy(String 原始路径,String 新路径),能复制所有文件,且名字和后缀名与源文件一致,在名字前拼接当前日期使用Scanner写入路径
- 未能加载文件或程序集“xxx”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集
- 让计划任务生成的文件中包含当前日期
- 如何每天备份,每天生成一个日期备份文件?(參考貼)
- 创建一个Date.text文件,获取当前的日期,将日期格式为“2013/02/14 05:20:00”的形式。然后一秒钟记录一次,将新的时间存入到文件中。
- 未能加载文件或程序集“xxx”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集
- 未能加载文件或程序集“xxx”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集
- 未能加载文件或程序集“System.Web.DataVisualization.Design”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集。
- 让计划任务生成的文件中包含当前日期
- 未能加载文件或程序集“xxx”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集
- 未能加载文件或程序集“xxx”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集
- Java中动态生成当前日期的文件
- Weblogic日志按日期,每日生成一个新文件
- 批处理 —— 每天生成一个以日期命名的文件(Win XP)
- [Matlab]未能加载文件或程序集“xx”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集。 Source: mscorlib HelpLink
- 未能加载文件或程序集“xxx”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集。
- 扫描一个目录下的所有文件,根据这些文件的创建日期生成一个文件夹,然后把这些文件移入这个文件夹下面
- 脚本文件中使用变量(得到当前时间,用来生成一个文件夹)
- 未能加载文件或程序集“BLL”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集。