宣言行を必要とする単純なプログラムを進行中です
read = new BufferedReader(new FileReader("marks.txt"));
と
行 = 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"
}
}
編集:これらの変数をクラス変数として宣言したい。使用するすべてのメソッドで同じ変数を再定義するという苦痛を経験したくありません。