问题描述:

每天都会生成一定的txt文件,txt文件当中含有复数个个人的信息,把每个个人信息都抽出来之后放到Excel文件的一览里面。

解决思路:

1.txt文件里面的信息有多件,每一件生成一个临时的文件。

2.读取临时的文件之后放到Excel的一览里面。

3.考虑到二次执行的时候,要把临时的文件和前一次的数据给删除。

talend的具体的流程如下图:

解释说明:

①为了第二次可以执行,所以在此处先删除临时文件夹里面的临时文件

代码如下:

// 当「コンポーネント」で、下記コードを書きます
// パラメータ「context.dataSourcePath」がContxtで、設定する、
outputDataConver.fileDel(context.dataSourcePath + "temp"); 
// 在「コード」⇒「ルーチン」で、新しいクラスを作成し、下記の方法を作成
// 一時ファイル削除
public static void fileDel(String path){
File file = new File(path);
if (file.exists()) {
File[] files = file.listFiles();
for (File fileItem : files) {
fileItem.delete();
}
}
}

②此处的目的是想把「tJava3」的代码都执行结束之后再向下执行。

生成方式是·「tJava5」⇒「右キーを押し」⇒「トリガー」⇒「サブジョブがOKの場合」

③④⑤为了实现在第二次执行的时候,把第一次执行的数据要删除的功能,再次要检索一下,当前的数据文件里面有没有当天的数据

③的生成方式是·「メタデータ」⇒「Excelファイル」⇒「右キーを押し」⇒「Excelファイル作成する」

④只是匹配两端的数据

⑤要判断有没有执行过一次数据,即当天的数据是否含有

// 当日のデータがあれば、パラメータが”FLASE”を設定する
// パラメータ「context.dataDelFg 」がContxtで、設定する、初期値が”true”に設定する
if(( new SimpleDateFormat("yyyyMMdd").format(new Date())).equals(input_row.O) ){
context.dataDelFg = "false"; }

⑥临时的一个控件,为了方便加判断条件。添加方式是鼠标选择在控件「tJava5」⇒「右キーを押し」⇒「トリガー」⇒「条件付く実行」

if(order:1)的判断条件("false".equals(context.dataDelFg ))

if(order:2)的判断条件("true".equals(context.dataDelFg ))

⑦⑧⑨此处是想实现,删除当天的数据生成临时的文件

  ⑧处的设定如下

⑩处的实现利用临时生成的文件把目标文件给覆盖,即拷贝
⑪利用事前准备好的模板把临时生成的临时文件给恢复到最初的状态

⑫把单个txt文件里面的复数个个人信息给生成到,一个文件一个个人信息里面

			// キーワード:名前
String keyFileName =context.dataSourcePath + "氏名.txt";
List<String> keyFileNameList = outputDataConver.getKeyWord(keyFileName); // キーワード:性別
String keyFileSex = context.dataSourcePath + "性別.txt";
List<String> keyFileSexList = outputDataConver.getKeyWord(keyFileSex);
// キーワード:年齢
String keyFileAge = context.dataSourcePath + "年齢.txt";
List<String> keyFileAgeList = outputDataConver.getKeyWord(keyFileAge);
// キーワード:経験年数
String keyFileExperience=context.dataSourcePath + "経験.txt";
List<String> keyFileExperienceList = outputDataConver.getKeyWord(keyFileExperience);
// キーワード:最寄駅
String keyFileStation = context.dataSourcePath + "最寄駅.txt";
List<String> keyFileStationList = outputDataConver.getKeyWord(keyFileStation);
// キーワード:日本語レベル
String keyFileLevel = context.dataSourcePath + "日本語レベル.txt";
List<String> keyFileLevelList = outputDataConver.getKeyWord(keyFileLevel);
// キーワード:スキル
String keyFileSkill = context.dataSourcePath + "スキル.txt";
List<String> keyFileSkillList = outputDataConver.getKeyWord(keyFileSkill);
// キーワード:業種
String keyFileIndustry = context.dataSourcePath + "業種.txt";
List<String> keyFileIndustryList = outputDataConver.getKeyWord(keyFileIndustry);
// キーワード:希望単価
String keyFilePrice = context.dataSourcePath + "希望単価.txt";
List<String> keyFilePriceList = outputDataConver.getKeyWord(keyFilePrice); // 指定のパス下のファイル取得
String path = context.dataSourcePath +( new SimpleDateFormat("yyyyMMdd").format(new Date()))+ "\\";
List<String> fileNameList = outputDataConver.traverseFolder(path); for(String fi:fileNameList){
String name = fi.replace(path,"");
File file = new File(fi);
FileWriter writer=null;
try (InputStreamReader fr = new InputStreamReader(new FileInputStream(file), "SJIS");
BufferedReader reader = new BufferedReader(fr)) { String temp = ""; String kkcy1 = context.dataSourcePath + "temp/" + name.substring(0,name.length()-4);
String kkcy2= name.substring(name.length()-4, name.length()); int index = 0;
boolean flag = true;
boolean sexFlag = true;
boolean ageFlag = true; // TXTファイル内容読み取り
while ((temp = reader.readLine()) != null) { String nameStr = outputDataConver.keyWord(temp, keyFileNameList);
if (!"".equals(nameStr)){
if(!flag){
writer.close();
flag = true;
}
File fileText = new File(kkcy1 +"_" + index + kkcy2); writer=new FileWriter(fileText);
index = index + 1; writer.write("名前:" + nameStr.trim());
writer.write("\r\n");
writer.write("会社:" + name);
writer.write("\r\n");
sexFlag = false;
ageFlag = false;
flag = false;
} if (!sexFlag){
String sexStrHs = outputDataConver.keyWordSex(temp);
if(!sexStrHs.equals("")){
sexFlag = true;
writer.write("性別:" + sexStrHs.trim() );
writer.write("\r\n");
}
}
String sexStr = outputDataConver.keyWord(temp, keyFileSexList);
if (!"".equals(sexStr)){
writer.write("性別:" + sexStr.trim() );
writer.write("\r\n");
}
if (!ageFlag){
String ageStrHs = outputDataConver.keyWordAge(temp);
if(!ageStrHs.equals("")){
ageFlag = true;
writer.write("年齢:" + ageStrHs.trim() );
writer.write("\r\n");
} }
String ageStr = outputDataConver.keyWord(temp, keyFileAgeList);
if (!"".equals(ageStr)){
writer.write("年齢:" + ageStr.trim());
writer.write("\r\n");
} String experienceStr = outputDataConver.keyWord(temp, keyFileExperienceList);
if (!"".equals(experienceStr)){ writer.write("経験年数:" + experienceStr.trim());
writer.write("\r\n");
} String stationStr =outputDataConver. keyWord(temp, keyFileStationList);
if (!"".equals(stationStr)){
writer.write("最寄駅:" + stationStr.trim());
writer.write("\r\n");
} String levelStr = outputDataConver.keyWord(temp, keyFileLevelList);
if (!"".equals(levelStr)){
writer.write("日本語レベル:" + levelStr.trim());
writer.write("\r\n");
} String skillStr = outputDataConver.keyWord(temp, keyFileSkillList);
if (!"".equals(skillStr)){
writer.write("スキル:" + skillStr.trim().replace(",","、"));
writer.write("\r\n");
} String industryStr = outputDataConver.keyWord(temp, keyFileIndustryList);
if (!"".equals(industryStr)){
writer.write("業種:" + industryStr.trim());
writer.write("\r\n");
} String priceStr = outputDataConver.keyWord(temp, keyFilePriceList);
if (!"".equals(priceStr)){
writer.write("希望単価:" + priceStr.trim());
writer.write("\r\n");
}
} } catch(FileNotFoundException e) {
throw new Exception(e);
}finally{ if(writer != null) {
writer.close();
}
}
}

⑬⑭⑮⑯实现把每一个文件的个人信息写到Excel里面

⑬的设定

⑭的代码

			  String fileName = context.dataSourcePath + "temp/"+ ((String)globalMap.get("tFileList_1_CURRENT_FILE"));

			  File file = new File(fileName);
try (InputStreamReader fr = new InputStreamReader(new FileInputStream(file), "SJIS");
BufferedReader reader = new BufferedReader(fr)) { String temp = ""; String[] strTemp= {" ,"," ,"," ,"," ,"," ,"," ,"," ,"," ,"," ,"," ,",}; while ((temp = reader.readLine()) != null) {
System.out.print("Excel:"+temp);
if (temp.indexOf("名前:") >= 0){
strTemp[0] = temp.replace("名前:", "") + ",";
} if (temp.indexOf("性別:") >= 0){
strTemp[1] = temp.replace("性別:", "") + ",";
} if (temp.indexOf("年齢:") >= 0){
strTemp[2] = temp.replace("年齢:", "") + ",";
} if (temp.indexOf("経験年数:") >= 0){
strTemp[3] = temp.replace("経験年数:", "") + ",";
} if (temp.indexOf("最寄駅:") >= 0){
strTemp[4] = temp.replace("最寄駅:", "") + ",";
}
if (temp.indexOf("日本語レベル:") >= 0){
strTemp[5] = temp.replace("日本語レベル:", "") + ",";
}
if (temp.indexOf("スキル:") >= 0){
strTemp[6] =temp.replace("スキル:", "") + ",";
}
if (temp.indexOf("業種:") >= 0){
strTemp[7] = temp.replace("業種:", "") + ",";
}
if (temp.indexOf("希望単価:") >= 0){
strTemp[8] = temp.replace("希望単価:", "") + ",";
} if (temp.indexOf("会社:") >= 0){
strTemp[9] = temp.replace("会社:", "") + ",";
}
} StringBuilder strBuData = new StringBuilder();
for(int i = 0; i < strTemp.length; i++){
strBuData.append(strTemp[i]);
} context.txtStr = strBuData.toString();
row1.txtStr = context.txtStr; } catch(FileNotFoundException e) {
throw new Exception(e);
}

  ⑯的设定

常量的设定

talend工具整理文件并出力文件到Excel当中的更多相关文章

  1. 从java文件和CS文件里查询方法使用次数工具

    前几天,领导让我找一下老系统(Java)里getRemoteUser方法都哪个文件用了,package是什么,方法被调用了多少次,当时因为着急,所以,直接人工找的,但是以后要是再出现,人工找就太讨厌了 ...

  2. 文件夹差异文件对比工具 meld

    /***************************************************************************************** * 文件夹差异文件 ...

  3. 最终版-perl工具解析数据库的报告文件0120

    ********************需要根据自己的实际环境修改哦**************************** ******************** 1. 收集awr报告样本   a ...

  4. java使用io创建文件与删除文件的工具类

    java中对于文件的操作,是再常见不过了.以下代码是自己代码中所用到的工具类,仅供参考. import java.io.File; import java.io.IOException; /** * ...

  5. 文件夹或者文件比对工具 Beyond Compare

    文件夹或者文件比对工具 Beyond Compare 之前有同事离职了.       没有工作交接.       同事的代码有一部分也没有提交版本库.       结果就是线上的代码和版本库中的文件数 ...

  6. 转载:.Net 程序集 签名工具sn.exe 密钥对SNK文件 最基本的用法

    .Net 程序集 签名工具sn.exe 密钥对SNK文件 最基本的用法 阐述签名工具这个概念之前,我先说说它不是什么: 1.它不是用于给程序集加密的工具,它与阻止Reflector或ILSpy对程序集 ...

  7. 使用rdbtools工具来解析redis rdb文件

    工欲善其事必先利其器,日常工作中,好的工具能够高效的协助我们工作:今天介绍一款用来解析redis rdb文件的工具,非常好用.会之,受用无穷! 一.rdbtools工具介绍 源码地址:https:// ...

  8. Windows文件夹、文件源代码对比工具--WinMerge

    /********************************************************************** * Windows文件夹.文件源代码对比工具--WinM ...

  9. 使用 ASMCMD 工具管理ASM目录及文件

    ============================== -- 使用ASMCMD 工具管理ASM目录及文件 --============================== 在ASM实例中,所有的 ...

随机推荐

  1. linux系列(二十一):chmod命令

    1.命令格式 chmod [-cfvR] [--help] [--version] mode file 2.命令功能 用于改变文件或目录的访问权限,用它控制文件或目录的访问权限. 3.命令参数 必要参 ...

  2. 异步协程asyncio+aiohttp

    aiohttp中文文档 1. 前言 在执行一些 IO 密集型任务的时候,程序常常会因为等待 IO 而阻塞.比如在网络爬虫中,如果我们使用 requests 库来进行请求的话,如果网站响应速度过慢,程序 ...

  3. C++标准库分析总结(四)——<Vector、Array、Forward_list设计原则>

    本节主要总结标准库Vector和Array的设计方法和特性以及相关迭代器内部特征 1.Vector 1.1 Vector 内部实现 Vector是自增长的数组,其实在标准库中没有任何一种容器能原地扩充 ...

  4. GFS中元数据的管理

    GFS 元数据(metadata)中包含三部分: GFS元数据的管理方式: 1.文件的命名空间和块的命名空间: 采用持久化的方式. 对于文件和块的命名空间以及从文件到块的映射:通过向操作日志登记修改而 ...

  5. Hadoop优化 操作系统优化

    1.优化文件系统,修改/etc/fstab 在defaults后面添加noatime,表示不记录文件的访问时间. 修改为: 如果不想重新启动操作系统使配置生效,那么应该执行: # mount -o r ...

  6. 2018-2019-2 网络对抗技术 20165202 Exp9 Web安全基础

    博客目录 一.实践内容 跨站脚本攻击XSS 跨站请求伪造CSRF SQL注入攻击 二.实验中遇到的问题及解决 三.基础问题回答 四.实验总结 一.实践内容 本实践的目标理解常用网络攻击技术的基本原理. ...

  7. TynSerial自定义对象的序列(还原)

    TynSerial自定义对象的序列(还原) TynSerial是咏南中间件封装的支持数据二进制序列(还原)的类. 对于ORM来说,序列类必须序列(还原)自定义对象. 1)定义一个自定义对象 type ...

  8. 超详细Qt5.9.5移植攻略

    本文就来介绍下如何将Qt5.9.5移植到ARM开发板上. 以imx6开发板为例,使用Ubuntu14.04虚拟机作为移植环境. 准备工作 1.主机环境:Ubuntu14.04: 开发板:启扬IAC-I ...

  9. LoadRunne遇到的一些问题FAQ(持续更新...)

    1.LR11破解完成,添加License失败,报错License security violation Loadrunner11破解成功后,用deletelicense.exe工具把License全删 ...

  10. Docs-.NET-C#-指南-语言参考-预处理器指令:#line(C# 参考)

    ylbtech-Docs-.NET-C#-指南-语言参考-预处理器指令:#line(C# 参考) 1.返回顶部 1. #line(C# 参考) 2015/07/20 借助 #line,可修改编译器的行 ...