public void ReadFiles(String path)//"c:/1.txt"
{
try{
String s=path;
File f = new File(s);
if(!f.isFile())
{
System.out.println("input is not a file!");
return;
}
BufferedReader inf = new BufferedReader(new FileReader(s));
String c = inf.readLine();
int i = 0;
while(c!=null)
{
System.out.println(c);
i++;
System.out.println(i);
c = inf.readLine();
}
}
catch(Exception e)
{} }
{
try{
String s=path;
File f = new File(s);
if(!f.isFile())
{
System.out.println("input is not a file!");
return;
}
BufferedReader inf = new BufferedReader(new FileReader(s));
String c = inf.readLine();
int i = 0;
while(c!=null)
{
System.out.println(c);
i++;
System.out.println(i);
c = inf.readLine();
}
}
catch(Exception e)
{} }
1
Arsenal 0 Juventus 4
2
Manchester 1 Taranto 0
3
Coventry 1 Chelsea 1
4
Roma 1 Cagliari 0
5
Inter 4 Lecce 0
6
Rangers 1 Hearts 1
7
Tottenham 1 AstonVilla 2
8
Sheffield 0 Leeds 0
9这是打印出来结果!
import java.io.*;class LineCount {
public static int lines = 0; public static void lc(InputStreamReader isr)throws IOException {
int c = 0;
while ((c = isr.read()) != -1) {
if (c == '\n') {
lines++;
}
}
++lines;
} public static void main(String args[]) {
FileReader fr;
try {
fr = new FileReader("text.txt");
lc(fr);
}
catch (IOException e) {
return;
}
System.out.println(lines + "");
}
}
那个patch 文件地址应该打在哪里啊? tsd3698(七夜)
的方法可以算出来了!但是,能有不用try 这个语句的方法吗?
path你只要调用这个方法体,并把参数传进去就好拉!
哈哈!