【工具】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 ...
随机推荐
- 3 Task中的一些枚举 创建时候的、continue时候的
创建时常用的枚举: None.PreferFairness.LongRunning.AttacthedToParent.DenyChildAttach.HideScheduler AttacthedT ...
- Leetcode 171 Excel Sheet Column Number 字符串处理
本质是把26进制转化为10进制 A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 class Solution ...
- Android sendToTarget
在使用message进行handler的数据交互的时候不可避免的会使用到message作为数据的载体,可是在使用message的时候有人会直接new一个message,有人会使用handler.obt ...
- 线程池;java的线程池的实现原理;适用于频繁互动(如电商网站)
线程池是一种多线程处理形式,处理过程中将任务加入到队列,然后在创建线程后自己主动启动这些任务.线程池线程都是后台线程.每一个线程都使用默认的堆栈大小,以默认的优先级执行.并处于多线程单元中. 假设某个 ...
- WPF ListView的使用
<Window x:Class="XamlTest.Window14" xmlns="http://schemas.microsoft.com/win ...
- mysql 视图,存储过程,游标,触发器,用户管理简单应用
mysql视图——是一个虚拟的表,只包含使用时动态查询的数据 优点:重用sql语句,简化复杂的SQL操作,保护数据,可以给用户看到表的部分字段而不是全部,更改数据格式和表现形式 规则: 名称唯一,必须 ...
- JAVASCRIPT高程笔记-------第八章 浏览器BOM对象
8.1 window对象--表示一个浏览器的实例 在全局作用域中声明的任何变量.函数都会变成window对象的属性和方法,与之直接定义window对象的属性的区别是 window.xxx 可以通过 ...
- 【C#】解决MouseHook捕获鼠标动作,在有些电脑上SetWindowsHookEx失败返回0的问题
原文:[C#]解决MouseHook捕获鼠标动作,在有些电脑上SetWindowsHookEx失败返回0的问题 最近在debug鼠标位置捕获的功能时发现在其中的一台开发电脑上,SetWindowsHo ...
- 支持chrome30下载文件
function downloadX(url ,fileName){ const xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr ...
- window下golang生成静态库给C语言调用
buidmod为c-archive能在window下生成 ,c-shared则不行 1.golang生成c-archive静态库 main.go package main import "C ...