java方法 调用 问题

来源:互联网 发布:软件防火墙有哪些 编辑:程序博客网 时间:2024/05/22 14:29
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;


public  class Writer {
int n=0;
String bookName;
public  void addComputerB(String name)
{
++n;
bookName = name;
try {
FileWriter filew= new FileWriter(new File("计算机类.txt"));
BufferedWriter br = new BufferedWriter(filew);
br.write(bookName);
br.newLine();
br.flush();
br.close();
filew.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String getName(String Bname)
{
return Bname;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
addComputerB(getName("《核心技术》"));//为什么在此处提示有问题,说必须将方法改成静态的 啥原因呢?
System.out.println(n);
}

}

0 0