有一个m1.txt文件, 里面有这样三行数据:
12_4_4.txt
12_5_1.txt
12_5_2.txt这三行数据是本目录下的三个文件名,里面分别有15360个数据,我想写个程序,先去读m1.txt,然后读出3个String,再用这3个String去读取3个文件,可是程序就老是只读第一个就跳出,但不给任何错误提示,求各位大侠帮帮忙,多谢多谢! import java.util.*;
import java.io.*;
import java.lang.*;
import java.lang.Math;class temp
{
public static void main(String[] args) throws IOException
{ int i, j, k;
String function = "";
String instance_file = "";
String gender = "";
/********************** Enter the file name ********************/
try{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("Now Enter the file you want to train");
instance_file = br.readLine();
}catch(IOException ioe){
System.err.println("IOException: " + ioe.getMessage());
}
System.out.println("the file is " + instance_file);
/********************** Read the file ********************/
try
{
File in = new File(instance_file); FileInputStream file = new FileInputStream(in);
int length = (int)in.length();
byte[] length_byte = new byte[length]; file.read(length_byte);
String s = new String(length_byte);
s = s.replaceAll("\n", "");
String[] result = s.split("\\s");
for (i=0; i<result.length; i++)
System.out.println("result["+i+"] = " + result[i]);//这里能够成功输出3个文件名
for (i=0; i<result.length; i++)
{
System.out.println("Now training file " + result[i]);//这里只输出第一个文件名,说明for循环没起作用,不明白为什么
// Nodes' Values
double [] Input_in = new double[15360];
double [] Input_out = new double[15361];
/********************** Read the instance ********************/
try
{ File in2 = new File(result[i]);
FileInputStream file2 = new FileInputStream(in2);
int length2 = (int)in2.length();
byte[] length_byte2 = new byte[length2];
file2.read(length_byte2);
String s2 = new String(length_byte2);
s2 = s2.replaceAll("\n", "");
String[] result2 = s2.split("\\s");
for (i=0; i<result2.length; i++)
{
Input_in[i] = Double.parseDouble(result2[i]);
Input_out[i+1] = Input_in[i]/255;
}
}
catch (IOException e)
{
System.out.println("Could not read file: " + result[i]);
}
}
}
catch (IOException e)
{
System.out.println("Could not read file: " + instance_file);
}
}
}
12_4_4.txt
12_5_1.txt
12_5_2.txt这三行数据是本目录下的三个文件名,里面分别有15360个数据,我想写个程序,先去读m1.txt,然后读出3个String,再用这3个String去读取3个文件,可是程序就老是只读第一个就跳出,但不给任何错误提示,求各位大侠帮帮忙,多谢多谢! import java.util.*;
import java.io.*;
import java.lang.*;
import java.lang.Math;class temp
{
public static void main(String[] args) throws IOException
{ int i, j, k;
String function = "";
String instance_file = "";
String gender = "";
/********************** Enter the file name ********************/
try{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("Now Enter the file you want to train");
instance_file = br.readLine();
}catch(IOException ioe){
System.err.println("IOException: " + ioe.getMessage());
}
System.out.println("the file is " + instance_file);
/********************** Read the file ********************/
try
{
File in = new File(instance_file); FileInputStream file = new FileInputStream(in);
int length = (int)in.length();
byte[] length_byte = new byte[length]; file.read(length_byte);
String s = new String(length_byte);
s = s.replaceAll("\n", "");
String[] result = s.split("\\s");
for (i=0; i<result.length; i++)
System.out.println("result["+i+"] = " + result[i]);//这里能够成功输出3个文件名
for (i=0; i<result.length; i++)
{
System.out.println("Now training file " + result[i]);//这里只输出第一个文件名,说明for循环没起作用,不明白为什么
// Nodes' Values
double [] Input_in = new double[15360];
double [] Input_out = new double[15361];
/********************** Read the instance ********************/
try
{ File in2 = new File(result[i]);
FileInputStream file2 = new FileInputStream(in2);
int length2 = (int)in2.length();
byte[] length_byte2 = new byte[length2];
file2.read(length_byte2);
String s2 = new String(length_byte2);
s2 = s2.replaceAll("\n", "");
String[] result2 = s2.split("\\s");
for (i=0; i<result2.length; i++)
{
Input_in[i] = Double.parseDouble(result2[i]);
Input_out[i+1] = Input_in[i]/255;
}
}
catch (IOException e)
{
System.out.println("Could not read file: " + result[i]);
}
}
}
catch (IOException e)
{
System.out.println("Could not read file: " + instance_file);
}
}
}
{
Input_in[j] = Double.parseDouble(result2[j]);
Input_out[j+1] = Input_in[j]/255;
}把这一段的i都改成j就可以了。