我有一个简单的程序正在进行中,需要声明行
读取 = 新 BufferedReader(新 FileReader(“marks.txt”));
和
line = read.readLine();
成为类变量。我该怎么做?
这是我到目前为止编写的代码。
import java.io.*;
import java.math.*;
public class WriteKong
{
public static String line;
public static BufferedReader read;
public static PrintWriter write;
public static void main(String[] args) throws IOException
{
read = new BufferedReader(new FileReader("marks.txt"));
line = read.readLine();
while(line != null)
{
System.out.println(line);
read.readLine();
}
}
public static void sort()
{
// THIS IS WHAT THE FUNCTION DOES:
// > check the fourth digit in the line
// > if there is no fourth digit then store the mark
// > if mark is less than 50 then write to "fail.txt"
// > if mark is 50 or greater then write to "pass.txt"
}
}
编辑:我希望将这些变量声明为类变量。我不想经历在我使用的所有方法中重新定义相同变量的痛苦。