/**
* @(#)Demo.java
*
*
* @author
* @version 1.00 2007/5/22
*/
import java.io.*;
public class Demo
{
public Demo()
{
}
public static void main(String[] args)
{
try{
int acount;
byte[] bInput=new byte[100];
String str=new String();
FileInputStream file=new FileInputStream(new File("xiaoxiao.txt"));
String s1="a";
String s2="A";
int num=0;
int number=0;
acount=file.read(bInput);
str=str+new String(bInput);
while(acount!=-1)
{
str=str.substring(num,++num);
if(str.equals(s1)&&str.equals(s2))
{
number++;
}
}
System.out.println(number);
System.out.println(str);
file.close();
return;
}catch(FileNotFoundException er)
{
System.out.println(er.getMessage());
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
catch(StringIndexOutOfBoundsException b)
{/**
* @(#)Demo.java
*
*
* @author
* @version 1.00 2007/5/22
*/
import java.io.*;
public class Demo
{
public Demo()
{
}
public static void main(String[] args)
{
try{
int acount;
byte[] bInput=new byte[100];
String str=new String();
FileInputStream file=new FileInputStream(new File("xiaoxiao.txt"));
String s1="a";
String s2="A";
int num=0;
int number=0;
acount=file.read(bInput);
str=str+new String(bInput);
while(acount!=-1)
{
str=str.substring(num,++num);
if(str.equals(s1)&&str.equals(s2))
{
number++;
}
}
System.out.println(number);
System.out.println(str);
file.close();
return;
}catch(FileNotFoundException er)
{
System.out.println(er.getMessage());
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
catch(StringIndexOutOfBoundsException b)
{
}
}
}
}
}
}
不知道那里出问题了,编译能通过,运行没反应...
我想判断文件里有多少个"A"和"a"....