【工具】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 ...
随机推荐
- BZOJ 1483 HNOI2009 梦幻布丁 名单+启示录式的合并
标题效果:特定n布丁.每个人都有一个颜色布丁,所有的布丁反复有一定的颜色变化的颜色,颜色反复询问的段数 数据范围:n<=10W 色彩数<=100W 启发式合并名单0.0 从来不写清楚 实际 ...
- Android 测试 Appium、Robotium、monkey而其他的框架或工具控制
1. Appium測试 (功能測试,用户接受度測试,黑盒測试) - Rating: 8 Website: http://appium.io/ Appium測试相当于黑盒測试. 仅仅是測试UI逻辑正确性 ...
- freemarker写select包(四)
freemarker写select包 1.宏定义 <#macro select id datas value="" key="" text="& ...
- ASP.NET Core Razor 视图起始页 - ASP.NET Core 基础教程 - 简单教程,简单编程
原文:ASP.NET Core Razor 视图起始页 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core Razor 视图起始页 上一章节中我们介绍了布局视图, ...
- Paxos—以选美比赛为例PPT
- WPF 将Bitmapsource转换到Emgu.cv.image
原文:WPF 将Bitmapsource转换到Emgu.cv.image Transform WPF BitmapSource to Emgu.CV.Image******* /// <summ ...
- wpf CefSharp 与 js交互
原文:wpf CefSharp 与 js交互 通过 NuGet 获取 CefSharp.WpF 组件. xmlns:cefSharp="clr-namespace:CefSharp.Wpf ...
- python_matplotlib cannot import name _thread on mac
最后的2行错误信息是 from six.moves import _thread ImportError: cannot import name _thread 1 2 发现是six出现了问题,用pi ...
- HDU 1027 以数列
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- Adapter的泛型
宗旨:GetView方法放在具体的Activity/Fragment里面实现,其他的均可以复用 /// <summary> /// 通用适配器:新建GetViewEvent委托+OnGet ...