filename
package com.enjoyor.soa.traffic.server.tms.controller;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
public class FileNameTest {
private static String readFile(String filename) {
filename = filename.trim();
if (readFiles.contains(filename)) {
//循环include,则直接返回
return "######Error to read " + filename +"\n";
}
BufferedReader reader = null;
try {
readFiles.add(filename);
reader = new BufferedReader(new FileReader(filename));
String line;
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
int includeIndex = line.indexOf(INCLUDE);
if (includeIndex >= 0) {
String file = line.substring(includeIndex + INCLUDE.length());
line = readFile(file);
sb.append(line);
} else {
sb.append(line + "\n");
}
}
readFiles.remove(filename);
return sb.toString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return null;
}
private static Set<String> readFiles = new HashSet<String>();
private static final String INCLUDE = "#include";
public static void main(String[] args) {
/**
* 文件内容如下:
-----------------
a.txt
A
#include b.txt
#include c.txt
#include d.txt
----------------
b.txt
B B
----------------
c.txt
C C C
----------------
d.txt
D D D D
#include b.txt
#include c.txt
---------------
e.txt
E E E E E
#include d.txt
#include e.txt
*/
String filename = "C:/Users/xujianjun/Desktop/a.txt";
System.out.println("Read a.txt---->");
String content = readFile(filename);
System.out.println(content);
filename = "C:/Users/xujianjun/Desktop/d.txt";
System.out.println("Read d.txt---->");
content = readFile(filename);
System.out.println(content);
filename = "C:/Users/xujianjun/Desktop/e.txt";
System.out.println("Read d.txt---->");
content = readFile(filename);
System.out.println(content);
}
}
filename的更多相关文章
- shell 1>&2 2>&1 &>filename重定向的含义和区别
当初在shell中, 看到">&1"和">&2"始终不明白什么意思.经过在网上的搜索得以解惑.其实这是两种输出. 在 shell 程 ...
- 织梦多语言站点,{dede:include filename=''/}引入问题
织梦模板include插入非模板目录文件出现"无法在这个位置找到"错误的解决办法 以下是dede V55_UTF8 查dede include标签手册 (3) include 引入 ...
- [Tool] SourceTree操作中遇到错误(Filename too long)的解决方案
[Tool] SourceTree操作中遇到错误(Filename too long)的解决方案 问题情景 使用SourceTree,可以方便开发人员使用图形化接口的Git指令来管理原始码.但是在Wi ...
- NodeJs:module.filename、__filename、__dirname、process.cwd()和require.main.filename
转载于: http://blog.csdn.net/bugknightyyp/article/details/17999473 module.filename:开发期间,该行代码所在的文件. __fi ...
- System.load(String filename)和System.loadLibrary(String libname)的区别
前言 之前一篇文章在写Native方法的时候,第一个步骤里面有这么一段代码 static { System.load("D:" + File.separator + "H ...
- primefaces p:dataExporter filename 支持中文 utf8
p:fileDownload and p:dataExporter : for p:fileDownload, the Content-Disposition header should be set ...
- ruby -- 基础学习(九)filename去除扩展名
Rails -- filename去除扩展名 简单例子:params[:upload]['preview'].original_filename 的值为templateOne.html.er ...
- The URL "filename" is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web
Sharepoint Error : The URL "filename" is invalid. It may refer to a nonexistent file or fo ...
- 大型文档源文件拆分编辑编译\include{filename}
大型文档,如果把所有的文字都录入在同一个.tex文件中,那个文件的体积是不可估量的,文件的结构式混乱不堪的,文字的定位也是令人头疼的.幸亏latex提供了结构化的处理命令---include. 命令\ ...
- git rm –cached filename
为了能重新忽略那些已经被track的文件,例如停止tracking一个文件但是又不从仓库中删除它.可以使用以下命令: 代码如下 git rm –cached filename 上面这个命令用于删除单个 ...
随机推荐
- [No0000151]菜鸟理解.NET Framework中的CLI,CLS,CTS,CLR,FCL,BCL
最下层蓝色部分是.NET Framework的基础,也是所有应用软件的基础..NET Framework不是凭空出来的,实际上API,COM+,和一些相关驱动依然是它的基石..NET Framewor ...
- [No0000105]java sdk 开发环境变量powershell 自动配置脚本
# 设置Java SDK 环境变量 $softwares = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Unin ...
- 【RMAN】RMAN-05001: auxiliary filename conflicts with the target database
oracle 11.2.0.4 运行以下脚本,使用活动数据库复制技术创建dataguard备库报错rman-005001: run{ duplicate target database for sta ...
- Flash builder 、flash cs6、 as 3.0研究
1.Flash/Actionscript3 载入资源文件方法考 http://zengrong.net/post/1107.htm 2.使用Flash Professional CS5和Flash B ...
- zookeeper 杂记
Zookeeper为了保证高吞吐和低延迟,在内存中维护了这个树状的目录结构,这种特性使得Zookeeper不能用于存放大量的数据,每个节点的存放数据上限为1M.
- delphi inttohex 整型到十六进制
inttohex from delphi help: Returns the hex representation of an integer. Unit SysUtils Category nume ...
- 【转】escape()、encodeURI()、encodeURIComponent()区别详解
escape().encodeURI().encodeURIComponent()区别详解 原文链接:http://www.cnblogs.com/tylerdonet/p/3483836.html ...
- python摸爬滚打之day03----基本数据类型(int,str,bool)
1.数据类型转换 字符串 ----> bool print( bool("hello") ) -----> True 数字----> bool print( b ...
- 内核atom机制
内核版本:linux2.6.22.6 硬件平台:JZ2440 驱动源码 atom_ipc_poll_key_int_drv.c : #include <linux/module.h> #i ...
- 写一致性原理以及quorum机制
(1)consistency,one(primary shard),all(all shard),quorum(default)我们在发送任何一个增删改操作的时候,比如 PUT /index/type ...