别晕啊,给我一点希望好不好
用stream怎么做?是循环读吗
我是一次把它读出来BufferedReader br=new BufferedReader(new FileReader("C:\\sp3.log")); 怎样循环读
用stream怎么做?是循环读吗
我是一次把它读出来BufferedReader br=new BufferedReader(new FileReader("C:\\sp3.log")); 怎样循环读
解决方案 »
- jquery异步上传图片
- 在html文件中需要调用2段jquery的代码,但是不能同时运行?
- 使用fckeditor,通过jsp往里面传值的写法
- 技术难难题:Type mismatch: cannot convert from int to String 加分的
- 转义字符问题
- 关于Tomcat和SQL sever连接的问题
- 请问JSF怎么对datatable加一个列按钮事件?
- 救人阿!javamail的问题,俺实在搞不懂了
- 有一个很大表单,并不是每项都是必填的,这样添加数据库行的时候很麻烦.......
- 从数据库查询出来的数据 在前台怎么实现动态检索
- 有一个别人做的flash,没有加链接,我在给他放到网页上时,想加个链接,语句怎么写!(时刻在线)
- 急!为甚么用<jsp:setProperty>设置bean的属性不起作用?
public class textsearch {
public static void main(String[] args)
{
try
{
int megamount=0;
BufferedReader br=new BufferedReader(new FileReader("C:\\sp3.log"));
String linestr= null;
String pstr = "Send To Mobile Message";
int i=0,j=0,m=0;
int pos=0;
while(true)
{
// String linestr=br.readLine();
//最好不要在循环内声明变量
inestr=br.readLine();
if(linestr==null) break;
else
{
System.out.println(linestr);
//int i=0,j=0,m=0;
// String pstr="Send To Mobile Message";
pos = 0;
do
{ pos=linestr.indexof(pstr, pos);
if(pos>-1){
megamount+=1;
}while (pos=-1)
/* for(i=0;i<linestr.length();i++)
{
if(linestr.charAt(i)==pstr.charAt(0))
{
m=i;
//if(linestr.charAt(m)==pstr.charAt(j))System.out.println("----
"+linestr.charAt(m)+"---------"+pstr.charAt(j));
for(j=0;j<pstr.length()&&m<linestr.length()&&linestr.charAt(m)
==pstr.charAt(j);m++,j++);
if(j==pstr.length())
{
megamount+=1;
}
}
}*/
}
}
System.out.println("The amout is -----------------"+megamount+"----------------------");
}catch(Exception e){}
}
}
好象用法如下:你可以试试
String s1="abcdefghiadss";
String s2="abc";
s1.regionMatches(true,1,s2,1,s1.length()) ;
参数1:指示是否忽略大小写
参数2:开始查找此字符串的位置
参数3:另一个字符串
参数4:另一个字符串内开始查找的地址
参数5:字符串长度
public class textsearch {
public static void main(String[] args)
{
try
{
int megamount=0;
BufferedReader br=new BufferedReader(new FileReader("C:\\sp3.log"));
String linestr= null;
String pstr = "o";
int i=0,j=0,m=0;
int pos=0;
while(true)
{
// String linestr=br.readLine();
//最好不要在循环内声明变量
linestr=br.readLine();
System.out.println(linestr);
if(linestr==null) break;
else
{
//int i=0,j=0,m=0;
// String pstr="Send To Mobile Message";
pos = -1;
do
{ pos=linestr.indexOf(pstr,pos+1);
if(pos>-1){
megamount+=1;
}
}while (pos>-1) ;
/* for(i=0;i<linestr.length();i++)
{
if(linestr.charAt(i)==pstr.charAt(0))
{
m=i;
//if(linestr.charAt(m)==pstr.charAt(j))System.out.println("----
"+linestr.charAt(m)+"---------"+pstr.charAt(j));
for(j=0;j<pstr.length()&&m<linestr.length()&&linestr.charAt(m)
==pstr.charAt(j);m++,j++);
if(j==pstr.length())
{
megamount+=1;
}
}
}*/
}
}
System.out.println("The amout is -----------------"+megamount+"----------------------");
}catch(Exception e){}
}
}另:
BufferedReader br=new BufferedReader(new FileReader(filename))不限制文件大小
谢谢hpy121!
很感谢!