想法由来:有时查看网页源代码的css文件内容,竟是恼人的压缩后代码(不换行),如下图所示-- 它的可读性很差,所以写了下面这个简单的程序,实现自动换行. 适用条件:遇到指定字符换行(本例中遇到'}'换行). 源代码: import java.io.File; import java.io.PrintWriter; import java.util.Scanner; public class test { public static void main(String[] args) throws…
想法由来:之前写读书报告时,遇到一些烦人的文献,总喜欢把注释作为括号内容放到正文中,使文章繁琐冗长,所以写了下面这个代码,剔除了括号内的内容. 适用条件:原txt文本中的括号使用正确,即左右括号匹配正确,且对应的一对左右括号之间不能换行. 主要思想:以段落作为处理对象,找到第一个左括号的位置后,定义一个计数器count赋初值为1,然后遍历该左括号之后的字符,若遇到左括号则count加1,若遇到右括号则count减1.当count的值为0时,说明左右括号匹配正确,已经找到了与第一个左括号对应的右括…
现在在Demo.txt中存在数据: ABC 需要将ABC从文本文件中读取出来 代码片: import java.io.*; class FileReaderDemo { public static void main(String[] args) throws IOException { //创建一个文件读取流对象,和指定名称的文件相关联. //要保证该文件是已经存在的,如果不存在,会发生异常FileNotFoundException FileReader fr = new FileReader…
页面 项目结构 html代码 <html> </head> <body> <form action="down/downLoad" method="post"> <input type="text" name="name"> <input type="submit" value="Submit" /> </fo…
package file; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.Date; public class ImportFile { public static void main(String[] args) {  System.out.println(new Date…
public String readTxtFile(String filePath) { StringBuffer appInfolistInput = new StringBuffer(); try { String encoding = "UTF8"; File file = new File(filePath); if (file.isFile() && file.exists()) { InputStreamReader read = new InputStre…
代码: /* 获取随机文件文字 */ public static String random(String path) {//路径 String name = null; try { //把文本文件中的数据存储到集合中 BufferedReader reader = new BufferedReader(new FileReader(path)); //定义集合数组 ArrayList<String> list = new ArrayList<String>(); String l…
name: Jack ; salary: 12000 name :Mike ; salary: 12300 name: Luk ; salary: 10030 name :Tim ; salary: 9000 name: John ; salary: 12000 name: Lisa ; salary: 11000 实现第一种:读写都是操作txt文本 inFileName = 'file.txt' outFileName = 'file2.txt' with open(inFileName) a…
/*这是第100000份数据,要截取出100000*/ String s="这是第100000份数据"; String s1 = s.substring(s.indexOf("第") + 1, s.indexOf("份")); /*判断指定字符出现了几次*/ public static int countStr(String str, char key) { int count = 0; for (int i = 0; i < str.le…
Java HashSet对txt文本内容去重(统计小说用过的字或字数) 基本思路: 1.字节流读需要去重的txt文本.(展示demo为当前workspace下名为utf-8.txt的文本) 2.对读取到的单个字节判断 (1)如果为字母或特殊字符.操作(2) (2)添加到HashSet中,如果HashSet.add()返回true代表该字符添加到HashSet失败,即字符未出现过,故对其做写操作.(展示demo写到的是当前workspace下的u.txt) (3)如果为中文字符,根据txt文本编码…