前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >(四)Java读写文件,合并成新的文件

(四)Java读写文件,合并成新的文件

作者头像
wolf
发布2020-09-21 09:42:28
8500
发布2020-09-21 09:42:28
举报
文章被收录于专栏:大数据分享大数据分享
文件一:

AppCrashed participate__recharge_activity participate_activity

AppClickAppViewScreen WebClickWebStay PlanMsgSendPrepare PlanConverted AppEnd

文件二:

App 崩溃 参与充值活动 参与活跃活动 App 元素点击 App 浏览页面 Web 元素点击 Web 视区停留 Web 浏览页面 同时在线人数(特殊心跳事件) 拍卖行交易买入 装备升级 好感度培养 道具商店点击 卡牌抽取 分享 剧情 钻石商店点击 PVP战斗 关卡PVE战斗 道具商店提交订单 道具商店支付订单 神魄升级(属性系统) 新手引导通过 角色升级 登录游戏 创建角色 道具产出 道具消耗 订单提交【钻石礼包】 订单购买【钻石礼包】 卡牌升级 完成日常任务 Push 点击 App 激活 注册账号 登陆账号 消息已准备 消息已发送 推送转化 App启动 $退出APP

文件读取工具:

package xxxx.com.test.file_acc; import java.io.*;

public class FileUtils { public static void readToBuffer(StringBuffer buffer,String filePath) throws IOException { InputStream is = new FileInputStream(filePath); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line = reader.readLine(); while (line != null){ // line为空说明读完了 // 将读到的内容添加到buffer中 buffer.append(line); buffer.append("\n"); // 读取下一行 line = reader.readLine(); } reader.close(); is.close(); }

代码语言:javascript
复制
public static String readFile(String filePath) throws IOException {
    StringBuffer sb = new StringBuffer();
    // 传入buffer和文件路径
    FileUtils.readToBuffer(sb,filePath);
    return sb.toString();
}

}

文件合并,执行:

package xxxx.com.test.file_acc; import java.io.*;

public class File_append { public static void main(String[] args) throws IOException { String filePath01 = "F:\Project\WordCount\src\main\java\xxxx\com\test\file_acc\file01"; String readFile01 = FileUtils.readFile(filePath01); String filePath02 = "F:\Project\WordCount\src\main\java\xxxx\com\test\file_acc\file02"; String readFile02 = FileUtils.readFile(filePath02);

代码语言:javascript
复制
    System.out.println(readFile01);
    System.out.println("\n-------------------\n");
    System.out.println(readFile02);
    System.out.println("\n-------------------\n");
    // 进行文件合并
    mergeFiles(readFile01,readFile02);

    String file03 = "F:\\Project\\WordCount\\file03.txt";
    String read = FileUtils.readFile(file03);
    System.out.println(read);
}


public static void mergeFiles(String br1, String br2) throws IOException {
    // 写入的路径
    PrintWriter pw = new PrintWriter("file03.txt");

    // 用数组将读取的数据进行切分
    String[] split1 = br1.split("\n");
    String[] split2 = br2.split("\n");
    for (int i = 0; i < split1.length; i++) {
        // 开始将两个文件的数据写入到一起
        pw.println(split1[i]+"\t"+split2[i]);
        // 每行刷新
        pw.flush();
    }
    pw.close();
}

}

输出结果:

AppCrashed App 崩溃 participate__recharge_activity 参与充值活动 participate_activity 参与活跃活动

AppClick App 元素点击
AppClick App 元素点击

AppViewScreen App 浏览页面

WebClick Web 元素点击
WebClick Web 元素点击

WebStay Web 视区停留

pageview Web 浏览页面 acu 同时在线人数(特殊心跳事件) auction_buy 拍卖行交易买入 equipmentupgrade 装备升级 haogandu 好感度培养 itemstoreclick 道具商店点击 lottery 卡牌抽取 share 分享 story 剧情 zuanshistoreclick 钻石商店点击 pvpbattle PVP战斗 pvebattle 关卡PVE战斗 StoreSubmitOrder 道具商店提交订单 StorePayOrder 道具商店支付订单 ShenpoUpgrade 神魄升级(属性系统) RookieGuidance 新手引导通过 RoleUpgrade 角色升级 RoleLogin 登录游戏 RoleCreate 创建角色 PropGenerate 道具产出 PropConsume 道具消耗 PackageSubmitOrder 订单提交【钻石礼包】 PackagePayOrder 订单购买【钻石礼包】 GuardUpgrade 卡牌升级 DailyTask 完成日常任务 AppOpenNotification Push 点击 AppInstall App 激活 AccountRegister 注册账号 AccountLogin 登陆账号
pageview Web 浏览页面 acu 同时在线人数(特殊心跳事件) auction_buy 拍卖行交易买入 equipmentupgrade 装备升级 haogandu 好感度培养 itemstoreclick 道具商店点击 lottery 卡牌抽取 share 分享 story 剧情 zuanshistoreclick 钻石商店点击 pvpbattle PVP战斗 pvebattle 关卡PVE战斗 StoreSubmitOrder 道具商店提交订单 StorePayOrder 道具商店支付订单 ShenpoUpgrade 神魄升级(属性系统) RookieGuidance 新手引导通过 RoleUpgrade 角色升级 RoleLogin 登录游戏 RoleCreate 创建角色 PropGenerate 道具产出 PropConsume 道具消耗 PackageSubmitOrder 订单提交【钻石礼包】 PackagePayOrder 订单购买【钻石礼包】 GuardUpgrade 卡牌升级 DailyTask 完成日常任务 AppOpenNotification Push 点击 AppInstall App 激活 AccountRegister 注册账号 AccountLogin 登陆账号

PlanMsgSendPrepare 消息已准备

PlanMsgSendDone 消息已发送
PlanMsgSendDone 消息已发送

PlanConverted 推送转化

AppStart App启动
AppStart App启动

AppEnd $退出APP

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文件一:
  • 文件二:
  • 文件读取工具:
  • 文件合并,执行:
  • 输出结果:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档