彩蛋!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写出记录工具的更多相关文章

  1. 电脑右键新建文本文档(txt)消失的解决办法

    其实只需要一个注册表就可以了 下载地址http://pan.baidu.com/s/1hr7r0fM 拿走不谢! 注册表的内容是这样的,你也可以新建一个文件把后缀名改成.reg然后把下面的内容copy ...

  2. fortran77读写文本文档

    PROGRAM WRITETEXT IMPLICIT NONE INTEGER,PARAMETER :: NE=!fortran90 语法定义变量 DOUBLE PRECISION A(,),B(,) ...

  3. windows快速创建文本文档的几个方法快捷键和

    1. 在平常使用电脑中要经常用到在左面创建文本文档txt最笨重的方法就是右键但是这样非常的慢,有没有什么快捷键呢 2. 快捷键 快捷键就是Win+R ,键入notepad 然后回车就可以编辑了 是不是 ...

  4. Java 写一段字符到指定的文本文档中,如果该文本文档不存在,则创建该文本文档

    写一段字符到指定的文本文档中,如果该文本文档不存在,则创建该文本文档 import java.io.File; import java.io.FileNotFoundException; import ...

  5. oracle数据库中将clob字段内容利用java提取出至文本文档中

    代码段: 1.执行clob转String public static String ClobToString(Clob sc) throws SQLException, IOException { S ...

  6. Java 把一个文本文档的内容复制到另一个文本文档

    src.txt放在工程目录下,dest.txt可创建,也可不创建.一旦运行程序,如果dest.txt不存在,将自行创建这个文本文档,再将src.txt中的内容复制到dest.txt import ja ...

  7. 怎样用DOS命令创建txt文本文档

    单击运行, 打开命令提示符. 例如在D盘创建文本文档,那么就先进入D盘,在后面写 D: 于是就进入了D盘怎样用DOS命令创建txt文本文档 然后在后面写命令 copy con 文件名.txt ,然后回 ...

  8. 文本文档中各字母出现次数汇总(java)

    package 字母频率统计; import java.io.*; public class Inputfile { public static void main(String args[]) { ...

  9. Java 单字节、多字节读取文本文档中的内容

    文本文档位于工程下. 鼠标右击工程,选择“new - File”,即可创建. 文本文档的格式:GBK 单字节读取 import java.io.File; import java.io.FileInp ...

随机推荐

  1. 史上最全最强SpringMVC详细示例实战教程【good】

    1)Spring MVC 在调用处理方法之前,在请求线程中自动的创建一个隐含的模型对象. 2)调用所有方法级的 标注了 @ModelAttribute 的方法,并将方法返回值添加到隐含的模型对象中. ...

  2. zedboard之GPIO驱动器(离FPGA直到LINUX申请书)

    笔者:xiabodan   资源: http://blog.csdn.net/xiabodan/article/details/24308373 1 EDK 大家知道我们在EDK中建立GPIO然后倒出 ...

  3. Leetcode 144 Binary Tree Preorder Traversal 二叉树

    二叉树的基础操作:二叉树的先序遍历(详细请看数据结构和算法,任意本书都有介绍),即根,左子树,右子树,实现方法中还有用栈实现的,这里不介绍了 /** * Definition for binary t ...

  4. matlab 高级函数

    2*randn(sz):0 均值,方差为 4(variance), standard deviation:标准差为 2: numel():returns the # of elements: nume ...

  5. matlab 工具函数 —— normalize(归一化数据)

    function x = normalize(x, mu, sigma) x = bsxfun(@minus, x, mu); x = bsxfun(@rdivide, x, sigma); end ...

  6. mysql/Java服务端对emoji的支持 专题

    关于utf8不支持emoji是因为emoji是用4个字节存储的字符,而mysql的utf8只能存储1-3个字节的字符.那就存不了呗 需要更改的地方:(1)Mysql服务器client,mysql,my ...

  7. 【转载】FusionSphere架构详解

    FusionSphere底层使用Xen架构: 1.单台物理机上建立hypervisor系统. 2.将所有单个hypervisor系统整合起来管理使用. 安装CNA节点,所有的物理服务器都会先成为CNA ...

  8. linux C 内存管理方式之半动态

    看到半动态申请内存,第一反应这是什么鬼? 实际上半动态内存申请很容易理解,在GNU C中使用alloca函数来实现 #include <stdlib.h> void *alloca (si ...

  9. mysql 优化 读写分离 主从复制

    1:mysql所在服务器内核 优化  ---------此优化可由系统运维人员完成 2:mysql配置参数优化(my.cnf) -------- 此优化需进行压力测试来进行参数调整 3:sql语句及表 ...

  10. jquery 点谁谁哭-隐式迭代

    <!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...