【工具】java 文本文档txt写出记录工具
彩蛋!http://abowman.com/google-modules/dog/
以下是自己小游戏生成人物经历的传记时保存txt所用到的工具类,功能简单,不多说什么,贴上代码:
package com.yy.diabio.v1.utils;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
/**
* 传记
* @author Administrator
*
*/
public class Biography {
/**
* 读一行写一行
* @param path
*/
public static void readLineAndWrite(String path,String pathout){
try {
File file = new File(path);
String expath= path.replace(".", "_re.");
expath=expath.replaceAll("fileImp", "fileExp");
System.out.println(expath);
//int index =path.lastIndexOf(".");
//File expFile = new File("D:/scc0511_others_r.net");
File expFile = new File(expath);
BufferedReader br = new BufferedReader(new FileReader(file));
PrintWriter out = new PrintWriter(new BufferedWriter(
new FileWriter(expFile, true)));
String line = null;
while ((line = br.readLine()) != null) {
out.println(line);
}
if (br != null) {
br.close();
}
if (out != null) {
out.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 书写append,新建时会刷新或者创建新的
* @param path
* @param pathout
*/
public static void writeBioGraPhy(String msg){
String path=getPath();
File file = new File(path);
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
PrintWriter out =null;
try {
out = new PrintWriter(new BufferedWriter(
new FileWriter(file, true)));
out.println(msg);
} catch (IOException e) {
e.printStackTrace();
}finally{
out.flush();
}
}
/**
* 测试路径
* @return
*/
public static String getPath() {
//构造时获取到项目的物理根目录
//String project_root = this.getClass().getResource("/").toString().replace("file:/", "");
String project_root=ReadPropertiesUtil.class.getResource("/").toString().replace("file:/", "");
//web pro
//project_root = project_root.substring(0,project_root.indexOf("/WEB-INF"));
project_root = project_root.substring(0,project_root.indexOf("/bin"));
String path=project_root+"/src"+"/Biography.txt";
//path=project_root+"/Role.txt";
return path;
}
/**
* bat启动文件使用路径
*/
/* public static String getPath() {
//构造时获取到项目的物理根目录
//String project_root = this.getClass().getResource("/").toString().replace("file:/", "");
String project_root=ReadPropertiesUtil.class.getResource("/").toString().replace("file:/", "");
//web pro
//project_root = project_root.substring(0,project_root.indexOf("/WEB-INF"));
//project_root = project_root.substring(0,project_root.indexOf("/bin"));
String path=project_root+"/src"+"/Biography.txt";
//path=project_root+"/Role.txt";
return path;
}*/
}
【工具】java 文本文档txt写出记录工具的更多相关文章
- 电脑右键新建文本文档(txt)消失的解决办法
其实只需要一个注册表就可以了 下载地址http://pan.baidu.com/s/1hr7r0fM 拿走不谢! 注册表的内容是这样的,你也可以新建一个文件把后缀名改成.reg然后把下面的内容copy ...
- fortran77读写文本文档
PROGRAM WRITETEXT IMPLICIT NONE INTEGER,PARAMETER :: NE=!fortran90 语法定义变量 DOUBLE PRECISION A(,),B(,) ...
- windows快速创建文本文档的几个方法快捷键和
1. 在平常使用电脑中要经常用到在左面创建文本文档txt最笨重的方法就是右键但是这样非常的慢,有没有什么快捷键呢 2. 快捷键 快捷键就是Win+R ,键入notepad 然后回车就可以编辑了 是不是 ...
- Java 写一段字符到指定的文本文档中,如果该文本文档不存在,则创建该文本文档
写一段字符到指定的文本文档中,如果该文本文档不存在,则创建该文本文档 import java.io.File; import java.io.FileNotFoundException; import ...
- oracle数据库中将clob字段内容利用java提取出至文本文档中
代码段: 1.执行clob转String public static String ClobToString(Clob sc) throws SQLException, IOException { S ...
- Java 把一个文本文档的内容复制到另一个文本文档
src.txt放在工程目录下,dest.txt可创建,也可不创建.一旦运行程序,如果dest.txt不存在,将自行创建这个文本文档,再将src.txt中的内容复制到dest.txt import ja ...
- 怎样用DOS命令创建txt文本文档
单击运行, 打开命令提示符. 例如在D盘创建文本文档,那么就先进入D盘,在后面写 D: 于是就进入了D盘怎样用DOS命令创建txt文本文档 然后在后面写命令 copy con 文件名.txt ,然后回 ...
- 文本文档中各字母出现次数汇总(java)
package 字母频率统计; import java.io.*; public class Inputfile { public static void main(String args[]) { ...
- Java 单字节、多字节读取文本文档中的内容
文本文档位于工程下. 鼠标右击工程,选择“new - File”,即可创建. 文本文档的格式:GBK 单字节读取 import java.io.File; import java.io.FileInp ...
随机推荐
- go语言刷leetcode - 14 Longest Common Prefix
func longestCommonPrefix(strs []string) string { { return "" } { ] } ; ; idx++ { ; i < ...
- Information Centric Networking Based Service Centric Networking
A method implemented by a network device residing in a service domain, wherein the network device co ...
- 第一泰泽(Tizen)智能手机发布在俄罗斯
请看下图: 这是韩国三星公司在俄罗斯境内公布的第一款泰泽(Tizen)智能手机(今年6月2日).这说明,Tizen操作系统没有死去. 在泰泽官网上将泰泽操作系统定义为:"The OS of ...
- python_简单的DB统计
import numpy as npimport pylab as pldates=['20170314','20170315','20170316','20170317','20170318','2 ...
- 关于 Swift 2.0 - 语言新特性与革新
随着刚刚结束的 WWDC 2015 苹果发布了一系列更新,这其中就包括了令人振奋的 Swift 2.0. 这是对之前语言特性的一次大幅的更新,加入了很多实用和方便的元素,下面我们就一起来看看这次更新都 ...
- jquery 可以给事件传参数
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- Delphi 10.2可以开发Linux桌面应用了
原始地址 https://community.embarcadero.com/blogs/entry/firemonkey-on-linux Delphi Linux编译器已经发布,现在无需等待 ...
- #467 – 使用UniformGrid 均分行和列(Use a UniformGrid for Evenly Spaced Rows and Columns)
原文 #467 – 使用UniformGrid 均分行和列(Use a UniformGrid for Evenly Spaced Rows and Columns) UniformGrid 布局面板 ...
- 重写combobox模板,实现支持过滤的combobox
先看效果图 客户提出需求后,首选在百度查找可靠方案 看了几个,效果都不理想, 大多是把isEditNable设置成true,IsTextSearchNable设置成false 再对itemsSourc ...
- UWP开发-获取设备唯一ID
EasClientDeviceInformation deviceInfo = new EasClientDeviceInformation(); this.showDeviceInfo.Items. ...