【发布时间】:2014-03-10 11:38:40
【问题描述】:
我需要计算文件中特定字符的数量。用户将指定我只需要检查文件中有多少个字符的字符。
package assignmentoneqone;
import java.util.Scanner;
import java.io.FileReader;
import java.io.File;
import java.io.IOException;
/**
*
* @author Hannes
*/
public class AssignmentOneQOne {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner kb = new Scanner(System.in);
String fileLoc;
String userChar;
//User specify the file and character
System.out.println("Enter the file name");
fileLoc = kb.nextLine();
System.out.println("Enter a character");
userChar = kb.nextLine();
File file = new File(fileLoc);
try
{
FileReader fw = new FileReader(file);
这是我应该搜索字符的地方。
}
catch(IOException e)
{
System.out.println("The file does not exist.");
}
}
}
【问题讨论】:
标签: java loops search count char