当前位置: 代码迷 >> Java相关 >> 文件流问题
  详细解决方案

文件流问题

热度:220   发布时间:2007-05-22 22:20:53.0
文件流问题

/**
* @(#)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"....

搜索更多相关的解决方案: 文件  

----------------解决方案--------------------------------------------------------
 别的没感觉的
只是觉得你用 throws比try catch  好的多.
 
----------------解决方案--------------------------------------------------------
if(str.equals(s1)&&str.equals(s2))
这一局应该是if(str.equals(s1)||str.equals(s2)),如果是逻辑与的话肯定一个都没有,因为s1和s2连个变量根本就不一样。
顺便问搂住一句,str=str+new String(bInput);这一条语句是什么意思啊,字符串也能这么加吗
----------------解决方案--------------------------------------------------------

是的...就是能这么加所以能用


----------------解决方案--------------------------------------------------------
  相关解决方案