彩蛋!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. 距离北京奥运还有359天,发布WPF版本的北京2008标志(下)

    原文:距离北京奥运还有359天,发布WPF版本的北京2008标志(下) 图片显示效果:  XAML代码: <Viewbox Width="463.548828" Height ...

  2. Apache和Tomcat的整合

    1.web架构 首先上图,解释web通用架构 通常情况下分为三大块 : ★ Web server :  通常情况下由 Apache Http Server  . IBM Http Server  .I ...

  3. C# 用XiliumCefGlue做浏览器,JS和C#相互调用

    原文:C# 用XiliumCefGlue做浏览器,JS和C#相互调用 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u013564470/artic ...

  4. React学习(3)——ref,key,PureComponent,bindActionCreator

    ref 如果在html里设置ref那么它就指向这个真实的DOM节点. 如果在组件里设置ref,那么它就指向这个组件实例的引用,和组件里面的this互等. 我们经常在表单input,select里使用, ...

  5. 不得不说,我太佩服node了,连openXML也搞定了!

    https://github.com/Ziv-Barber/officegen 开源项目地址 使用报告等有空完成!

  6. C++ CGI开发环境备录

    1. 安装apache2: apt-get install apache2 2. 配置用户目录 在/etc/apache2/apache2.conf中配置用户目录 <Directory /hom ...

  7. nginx+tomcat反向代理

    第一步:编辑nginx的配置文件 #服务转发一 upstream tomcat8080{ server 192.168.1.6:8080; } #服务转发二 upstream tomcat8081{ ...

  8. Bootstrap路径导航

    @{    Layout = null;}<!DOCTYPE html><html><head>    <meta name="viewport&q ...

  9. 一步一步造个IoC轮子(二),详解泛型工厂

    一步一步造个Ioc轮子目录 一步一步造个IoC轮子(一):Ioc是什么 一步一步造个IoC轮子(二):详解泛型工厂 一步一步造个IoC轮子(三):构造基本的IoC容器 详解泛型工厂 既然我说IoC容器 ...

  10. Medical Image Report论文合辑

    Learning to Read Chest X-Rays:Recurrent Neural Cascade Model for Automated Image Annotation (CVPR 20 ...