先读取test.txt文件内容,将其保存成一个字符串,然后根据hello查找即可
解决方案 »
- jni 可以调C++的应用程序服务器中的函数吗?
- 线程Interrupt基础问题 得分好贴
- hibernate 如果保证每次都从数据库查询?
- 我刚学WEB编程,问个关于JSTL函数标签的问题
- 求助:为什么服务发布成功了,在VIEW页面却只显示and now~~~~some service下面什么都没有了
- spring+hibernate+struts问题,高手帮帮我
- 200分寻求《Java Development with Ant》
- 请问如何将把java从xml中取到的数据输入pdf文件中?
- 关于jbulider7的问题!(要多少分给多少分,别大过900)
- 数组对象 fastJSON
- hibernate主键出错
- 请教一个传值问题
而我只想打印hello hello hello hello hello,怎么实现?
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new FileReader("c:\test.txt"));
String aa = br.readLine();
String[] bb = aa.split("hello#hello");
for(String s : bb){
System.out.println(s);
}
}
应为aa.split("hello");
从得到的数组个数考虑一下
第2:应为aa.split("hello"); 从得到的数组个数考虑一下。应该是aa.split("a");
但又有个问题了。如果我不知道文本里的内容,但我只知道里面肯定有"hello",我怎么样才能单独取出呢?
然后判断是否与hello匹配
你的想法是可以,但如果有这样的情况呢?hello hell o hello a b c 这里面就2个hello,按你的意思的话就
可以弄出3个了.难道真的没有办法吗?
BufferedReader br = new BufferedReader(new FileReader("C://aa.txt"));
String aa = br.readLine();
String[] bb = aa.split("hello");
for(int i=1;i<bb.length;i++){
System.out.print("hello ");
}
import java.net.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
public class c
{
public static void main(String[] args)
{
try
{
String ur="file:///g:/qq.txt";
URL MyURL=new URL(ur);
String str;
URLConnection con=MyURL.openConnection();
InputStreamReader ins=new InputStreamReader(con.getInputStream(),"gbk");
BufferedReader in=new BufferedReader(ins);
StringBuffer sb = new StringBuffer();
while ((str=in.readLine())!=null)
{
sb.append(str);
}
in.close();
Pattern p = Pattern.compile("(hello)");
Matcher m = p.matcher(sb.toString());
m.matches();
while(m.find())
{
System.out.print(" "+m.group(1)); }
}
catch (MalformedURLException mfURLe) {
System.out.println("MalformedURLException: " + mfURLe);
}
catch (IOException ioe) {
System.out.println("IOException: " + ioe);
}
}
}