分配给 String 属性的文本未正确存储

text assigned to String attribute does not store properly

我已将 txt 文件中的文本分配给三个属性,但每当我使用 Get 方法将这些属性中的任何一个调用到另一个 class 时,显示的值为 "null"。

此外,我已经确认这些值显示在方法 leerArchivo 中(每当我为 m_linea1-2-3 使用 println 时)。

请帮忙。

public class ArchivoCasillas 
{
    String m_linea1;
    String m_linea2;
    String m_linea3;

public void crearArchivo()
{
    try
    {
        FileWriter fw = new FileWriter("ReglasDelTablero.txt");
        BufferedWriter bw = new BufferedWriter(fw);
        PrintWriter pw = new PrintWriter(fw);

        bw.write("<7,0> , <0,0>");
        bw.newLine();
        bw.write("<4,1> , <7,2> | <2,7> , <5,5> | <1,2> , <7,4> | <0,4> , <2,5>");
        bw.newLine();
        bw.write("<7,7> , <3,6> | <6,4> , <3,5> | <4,0> , <2,1> | <2,4> , <0,3>");

        bw.close();
    } 
    catch(IOException e)
    {
        System.out.println("error");
    }
}

public void leerArchivo()
{
    String linea;
    int i = 1;
    try
    {
        FileReader fr = new FileReader("ReglasDelTablero.txt");
        BufferedReader br = new BufferedReader(fr);
        Tablero serpientesEscaleras = new Tablero();

        while( (linea = br.readLine() ) != null)
        {    
            switch(i)
            {
                case 1: m_linea1 = linea;
                break;
                case 2: m_linea2 = linea;
                break;
                case 3: m_linea3 = linea;
                break;
            }

            i++;
        }

        br.close();
    }
    catch(IOException e)
    {

    }
}

public String getM_linea1()
{
    return m_linea1;
}

}

问题已解决。这对我来说是一个概念问题。我在另一个 class 中创建了一个对象,但我从未使用该对象调用 leerArchivo 方法,因此,属性的值为空。留下答案以防将来对某人有用,因为我没有得到回复。