java io读写文件 怎么查找想要的数据
importjava.io.*;publicclassTest_Io{publicstaticvoidmain(String[]agea){Stringb=null;tr...
import java.io.*;
public class Test_Io {
public static void main(String [] agea) {
String b=null;
try {
BufferedReader in=new BufferedReader( new FileReader("C:\\Users\\xiaozhou\\Desktop\\javaa.txt"));
BufferedWriter ou=new BufferedWriter(new FileWriter("C:\\Users\\xiaozhou\\Desktop\\javax.txt"));
while((b=in.readLine())!=null){
ou.write(b);
System.out.print("复制成功");
}
in.close();
ou.close();
} catch (IOException e) {
System.out.print("找不到指定文件");
System.exit(0);
}
}
}
请问怎么查找文件中含有多少个 1 展开
public class Test_Io {
public static void main(String [] agea) {
String b=null;
try {
BufferedReader in=new BufferedReader( new FileReader("C:\\Users\\xiaozhou\\Desktop\\javaa.txt"));
BufferedWriter ou=new BufferedWriter(new FileWriter("C:\\Users\\xiaozhou\\Desktop\\javax.txt"));
while((b=in.readLine())!=null){
ou.write(b);
System.out.print("复制成功");
}
in.close();
ou.close();
} catch (IOException e) {
System.out.print("找不到指定文件");
System.exit(0);
}
}
}
请问怎么查找文件中含有多少个 1 展开
2个回答
展开全部
代码如下,在里的循环里面添加判断
public static void main(String [] agea) {
String b=null;
int count =0;
try {
BufferedReader in=new BufferedReader( new FileReader("C:\\Users\\xiaozhou\\Desktop\\javaa.txt"));
BufferedWriter ou=new BufferedWriter(new FileWriter("C:\\Users\\xiaozhou\\Desktop\\javax.txt"));
while((b=in.readLine())!=null){
ou.write(b);
for (int i=0;i<b.length();i++) {
int charAt = (int)b.charAt(i);
if(charAt == 1){
count++;
}
}
System.out.print("复制成功");
}
in.close();
ou.close();
} catch (IOException e) {
System.out.print("找不到指定文件");
System.exit(0);
}
}
那个count就是1的个数
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询