使用java编写一个删除空行的小程序,要考虑TAB符和ENTER换行等所有情况,请大虾贴代码。 使用java编写一个删除空行的小程序,要考虑TAB符和ENTER换行等所有情况,请大虾贴代码。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是有关正则表达式和java io的,请大虾帮忙啊! import java.io.File;import java.io.FileInputStream;import java.util.regex.Matcher;import java.util.regex.Pattern;import org.junit.After;import org.junit.Before;import org.junit.Test;public class NTest { private StringBuilder content = new StringBuilder(); private Pattern pattern = Pattern.compile("(\r\n)*", Pattern.DOTALL); @Before public void setUp() throws Exception { FileInputStream fis= null; try { fis = new FileInputStream(new File("c:/test.txt")); byte[] b = new byte[1024]; int len = -1; while ((len = fis.read(b)) != -1) { content.append(new String(b, 0, len)); } } finally { if(null != fis) fis.close(); } } @After public void tearDown() throws Exception { content = null; } @Test public void Ntest() { Matcher matcher = pattern.matcher(content); int g = matcher.groupCount(); System.out.println("groupCount="+g); while(matcher.find()){ System.out.println("finded it"); for (int i = 0; i < g ;i++){ System.out.println(matcher.group(i)); } break; } }}这个要怎么修改才能完成上面的功能啊? System.out.println(content.toString().replaceAll("\\s","")); 一个小问题,菜鸟求教!!!! java如何创建结构,怎么从文件装入?? pdfbox提取pdf文本,如果pdf中的字体本地没有,出现乱码 请教,JDBC能否调用SQL SERVER中的自定义函数? 庆五一,散点分 高分求助:谁用过poolman??~~~~~见者有分~~~~~谢谢! 急寻遍历图的算法? JTree中的节点项不能修改? 事件模型,请大家讨论,讲的好的加分 tomcat3.2.3问题(急,在线等待) 求commons-fileupload文件上传的封装代码 jdbc数据库插入问题
import java.io.FileInputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;import org.junit.After;
import org.junit.Before;
import org.junit.Test;public class NTest { private StringBuilder content = new StringBuilder(); private Pattern pattern = Pattern.compile("(\r\n)*", Pattern.DOTALL); @Before
public void setUp() throws Exception {
FileInputStream fis= null;
try {
fis = new FileInputStream(new File("c:/test.txt"));
byte[] b = new byte[1024];
int len = -1;
while ((len = fis.read(b)) != -1) {
content.append(new String(b, 0, len));
}
} finally {
if(null != fis)
fis.close();
}
} @After
public void tearDown() throws Exception {
content = null;
} @Test
public void Ntest() {
Matcher matcher = pattern.matcher(content);
int g = matcher.groupCount();
System.out.println("groupCount="+g);
while(matcher.find()){
System.out.println("finded it");
for (int i = 0; i < g ;i++){
System.out.println(matcher.group(i));
}
break;
}
}
}
这个要怎么修改才能完成上面的功能啊?