下面是我的代码,它打算获取两个.ckl文件,比较两个文件,添加新项目并创建一个新的合并文件。该程序在Netbeans中运行时可以正确执行,但是,当执行.jar时,该程序似乎未使用UTF-8编码文件。我对编程很陌生,想知道在什么地方或如何执行这种编码?

**我删除了Swing代码和其他行,以便仅显示我的方法,该方法完成所有比较和合并。

public void mergeFiles(File[] files, File mergedFile) {

ArrayList list = new ArrayList();

FileWriter fstream = null;

BufferedWriter out = null;

try {

fstream = new FileWriter(mergedFile, false);

out = new BufferedWriter(fstream);

} catch (IOException e1) {

e1.printStackTrace();

}

// Going in a different direction. We are using a couple booleans to tell us when we want to copy or not. So at the beginning since we start

// with our source file we set copy to true, we want to copy everything and insert vuln names into our list as we go. After that first file

// we set the boolean to false so that we dont start copying anything from the second file until it is a vuln. We set to true when we see vuln

// and set it to false if we already have that in our list.

// We have a tmpCopy to store away the value of copy when we see a vuln, and reset it to that value when we see an

Boolean copy = true;

Boolean tmpCopy = true;

for (File f : files) {

textArea1.append("merging files into: " + mergedFilePathway + "\n");

FileInputStream fis;

try {

fis = new FileInputStream(f);

// BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(mergedFile), "UTF-8"));

BufferedReader in = new BufferedReader(new InputStreamReader(fis));

String aLine;

while ((aLine = in.readLine()) != null) {

// Skip the close checklist and we can write it in at the end

if (aLine.trim().equals("")) {

continue;

}

if (aLine.trim().equals("")) {

continue;

}

if (aLine.trim().equals("")) {

continue;

}

if (aLine.trim().equals("")) {

// Store our current value of copy

tmpCopy = copy;

copy = true;

String aLine2 = in.readLine();

String aLine3 = in.readLine();

String nameLine = in.readLine();

if (list.contains(nameLine.trim())) {

textArea1.append("Skipping: " + nameLine + "\n");

copy = false;

while (!(aLine.trim().equals(""))) {

aLine = in.readLine();

}

continue; // this would skip the writing out to file part

} else {

list.add(nameLine.trim());

textArea1.append("::: List is now :::");

textArea1.append(list.toString() + "\n");

}

if (copy) {

out.write(aLine);

out.newLine();

out.write(aLine2);

out.newLine();

out.write(aLine3);

out.newLine();

out.write(nameLine);

out.newLine();

}

} else if (copy) {

out.write(aLine);

out.newLine();

}

// after we have written to file, if the line was a close vuln, switch copy back to original value

if (aLine.trim().equals("")) {

copy = tmpCopy;

}

}

in.close();

} catch (IOException e) {

e.printStackTrace();

}

copy = false;

}

// Now lets add the close checklist tag we omitted before

try {

out.write("");

out.write("");

out.write("");

} catch (IOException e) {

e.printStackTrace();

}

try {

out.close();

} catch (IOException e) {

e.printStackTrace();

}

}

filewriter 设置编码_将FileWriter的编码设置为UTF-8相关推荐

  1. 电子白板 矢量 编码_当涉及白板编码采访时,请记住准备

    电子白板 矢量 编码 by Andy Tiffany 通过安迪·蒂芙尼(Andy Tiffany) 当涉及白板编码采访时,请记住准备 (When it comes to whiteboard codi ...

  2. python2默认编码_解决Python2.x编码之殇

    Python编码问题一直困扰了我许久,之前有过一些总结,但并不系统,比较凌乱.当然python2.x编码问题本身,便是剪不断理还乱.本篇将系统介绍python2.x编程中会遇到的一些编码问题,并给出解 ...

  3. 北大青鸟消防设备类型编码_探测器该如何编码?即报警区域、探测区域的真正用途...

    <火灾自动报警系统设计规范> GB 50116-2013中说到 报警区域是将火灾自动报警系统的警戒范围按防火分区或楼层等划分的单元. 报警区域应根据防火分区或楼层划分:可将一个防火分区或一 ...

  4. python tkinter图片为什么要设置全局变量_为什么这里一定要设置全局变量

    下面是程序其中有个变量y如果不开始设置成全局变量,y=y+k;这里就会提示报错说使用了未赋值的局部变量!前提是我再设置其他(inti,z,k,y;)已经设置后不能使用//题目:输入某年某月某... 下 ...

  5. Java 如何设置时间_如何在Java中设置尊重用户操作系统设置的日期和时间格式

    我在Windows 7机器上运行Java应用程序,在该机器上,我的区域设置已设置为将日期格式设置为YYYY-mm- dd,将时间格式设置为HH:mm:ss(例如" 2011-06-20 07 ...

  6. 华硕计算机用户名默认,华硕路由器设置方法_华硕(ASUS)路由器怎么设置?-192路由网...

    问:华硕(ASUS)路由器怎么设置? 本人自己第一次设置路由器,这台了半天还是没有搞好. 请问新买的华硕路由器,要怎么设置才能上网? 答:一台新买回来的华硕路由器,要让它连接Internet上网,需要 ...

  7. java 判断zip文件编码_如何使用UTF-8编码打开java程序生成的zip文件

    我们的产品有一个导出功能,它使用ZipOutputStream压缩目录;但是,当您尝试压缩包含具有中文或日文字符的文件名的目录时,导出将无法正常工作.由于某种原因,压缩文件中的新文件的命名方式不同.以 ...

  8. 谷歌编码_如何通过学习编码赢得Google之旅

    谷歌编码 by MaskyS 通过MaskyS 如何通过学习编码赢得Google之旅 (How I won a trip to Google by learning to code) 设置场景 (Se ...

  9. 北大青鸟消防设备类型编码_北大青鸟JBF4372E编码型火灾声光警报器

    北大青鸟JBF4372E编码型火灾声光警报器 一,功能特点: 内置微处理器. 电子编码,编码方式与输出模块相同,编码范围1–200. 四总线通讯方式,其中信号线无极性,电源线有极性,占用一个回路地址. ...

最新文章

  1. 工资倒挂也刺激不了已是咸鱼的你
  2. 【pytorch】nn.GRU的使用
  3. Counting Bits(Difficulty: Medium)
  4. 测试用例设计方法_黑盒测试——测试用例设计方法
  5. 点击类名方法名如何连接到相应的Android源代码
  6. 大家好,我就是那个提【换手机壳颜色变app主题】需求的“产品经理”
  7. 常见的几种数组排序方法
  8. XTU,C语言,字母圣诞树
  9. 计算机 映射网络驱动器,映射网络驱动器
  10. Retrofit(Okhttp)Dns解析服务器域名异常时尝试使用服务器IP访问
  11. Typo: In word 问题解决。
  12. kanban 看板视图
  13. loop variable ‘numerator‘ creates a copy from type ‘const std::string‘ [-Wrange-loop-construct]
  14. 编译器与Debug的传奇:Grace Murray Hopper小传
  15. 快速切换IP的批处理!
  16. Oracle命令结束,更新语句oracle - ORA-00933:SQL命令未正确结束
  17. 谷歌五笔输入法电脑版_新手学拼音还是学五笔打字(看完你就明白)
  18. arcengine 面积单位转换
  19. html5 监控系统界面,基于WEB服务器实现监控系统的视频图像显示
  20. 分布式事务的BASE理论

热门文章

  1. python比较excel中两列数据_python入门之对比两份excel表格数据
  2. OVIRT安装NVIDIA- P100实现GPU虚拟化
  3. nuxt可以直接编译HTML标签,Nuxt
  4. 2012-9-5 白色风车、心雨、退后 忆往事
  5. linux 的i18n 文件夹,linux i18n文件分析
  6. go语言defer使用
  7. 手机铃声并清理掉了怎么办
  8. 邮件营销:取悦用户的18个标题模式
  9. Vue和Elementui的关系
  10. 小程序入门到精通一篇就够了!