这里老是报错;Syntax error on token ")", ; expected 怎么解?

import java.io.File;
import java.io.RandomAccessFile;
public class p145_7{
public static void main(String[] args){
String cat(File file){//老是报错怎么解?
RandomAccessFile input=null;
String Line=null;
try {
input=new RandomAccessFile(file,"r");
while((Line=input.readLine())!=null){
System.out.print(Line);
}
}catch(Exception e){
System.out.print(e);
}finally{
if(input!=null)
input.close();
}
}
}
}

 改成
 public class p145_7{
 String cat(File file) throws IOException{//老是报错怎么解?//方法定义不能放在main里面,放在类里面
    RandomAccessFile input=null;
    String Line=null;
    try {
    input=new RandomAccessFile(file,"r");
    while((Line=input.readLine())!=null){
    System.out.print(Line);
    }
    }catch(Exception e){
    System.out.print(e);
    }finally{
    if(input!=null)
    input.close();
    }
public static void main(String[] args){

}
}

谢谢,非常感谢,刚学java 很多不懂 谢谢您的帮助

楼上解释的对,但是方法没有返回值要用void,方法里面少一个大括号,还是会报错的。另外已经抛出了异常就不要在里面再捕获了,直接都抛出就好。
正确的是:

 void cat(File file) throws IOException {
        RandomAccessFile input = null;
        String Line = null;
        input = new RandomAccessFile(file, "r");
        while ((Line = input.readLine()) != null) {
            System.out.print(Line);
        }
        if (input != null)
            input.close();
    }

    public static void main(String[] args) {
        City test  = new City();
        try {
            test.cat(new File("test.txt"));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

给你一些建议:

开始在文本编辑器中写代码时,记得要写框架,比如把整体框架写好,比如先写这个:

 private void cat(File file){
 }

注意括号一定要写两个,不管你要往里面放什么,都先把括号的右半部分写好。然后再写这个方法具体的内容。

最后再写测试的主方法就行了。

用IDE环境来编写,不要修改整体文本结构,并且有高亮显示,有提示,就不会出错。