我想打印存储的数组值。但是当我这样做时,它只打印空值。我的代码有什么问题。当我检查数组长度()时。它打印长度。但是当我尝试检索值时,它只给出空值。
public class StoreVal
{
static String[] values1=new String[100];
static String[] kmvalues1=new String[200];
public static void setvalues()
{
try
{
@SuppressWarnings("resource")
BufferedReader b1=new BufferedReader(new FileReader("d://values//kmeans0.txt"));
@SuppressWarnings("resource")
BufferedReader b2=new BufferedReader(new FileReader("d://values//kmeans1.txt"));
@SuppressWarnings("resource")
BufferedReader b3=new BufferedReader(new FileReader("d://values//kmeans2.txt"));
@SuppressWarnings("resource")
BufferedReader b4=new BufferedReader(new FileReader("d://values//kmeans3.txt"));
String km1 = null;
String km2 = null;
String km3 = null;
String km4 = null;
while((km1=b1.readLine())!=null)
{
int i=0;
values1[i]=km1;
System.out.println(values1[i]);
}
}
catch(Exception e)
{
e.printStackTrace();
}
values();
}
public static void values()
{
for(int x=0;x<values1.length;x++)
{
System.out.println(values1[x]); // this line prints only null
}
}
public static void main(String[] args)
{
setvalues();
}
}