PS: все целые числа в файле состоят из более чем одной цифры.
Я хочу ввести матрицу 1 xn из текстового файла в java-программе.Я могу ввести матрицу с однозначными числами с помощью следующего кода, предложить решения, которые бы изменили то же самое.
import java.util.*;
import java.io.*;
class New_data{
public int[][] allocation= new int[25][25];
public int[][] need= new int[25][25];
public int[][] max= new int[25][25];
public int[] available=new int[25];
public int rows=0,col=0;
int count_flag=0;
void input_avaliable()
{
System.out.println("Enter the available matrix\nDimensions: " + col+":1");
}
void readfile(String s,int arr[][]) throws IOException
{
File file= new File(s);
FileInputStream fis= new FileInputStream(file);
InputStreamReader isr= new InputStreamReader(fis);
BufferedReader br= new BufferedReader(isr);
String line;
int i=0,j=0;
int shift=0; //shift int is used to convert char array to int
char[] ch=new char [50];
while((line = br.readLine()) != null)
{
if(count_flag==0)
{
rows++;
col=(line.length());
col=col/2;
}
else{}
ch=line.toCharArray();
shift=0;
for(j=0;j<col;j++)
{
arr[rows-1][j]=ch[j+shift];
shift++;
}
}
count_flag=1;
br.close();
}
void need() throws ArrayIndexOutOfBoundsException
{
Scanner sc=new Scanner(System.in);
for(int i=0;i<rows;i++)
{
for(int j=0;j<=col;j++)
{
need[i][j]=max[i][j]-allocation[i][j];
}
}
}
}
class Bankers{
public static void main(String args[]) throws IOException
{
New_data Data=new New_data();
String location=new String("allocation.txt");
Data.readfile(location,Data.allocation);
location="max.txt";
Data.readfile(location,Data.max);
Data.need();
}
}
Этот код правильно выводит два массива, но завершается неудачно, если во входном файле нет однозначных целых чисел.