안녕하세요. 안녕하세요. 안녕하세요. 안녕하세요. 다른 프로젝트의 코드를 변환 할 때 문제가있어 도움이 필요합니다. 'readFile'메서드에서 파일을 읽을 때 정수로 String을 구문 분석하려고합니다. 그러나,어레이가 필요하지만 발견되었습니다.
안부를, 마이크를
어떤 도움이 감사를
import java.util.*;
import java.io.*;
public class JavaApplication1
{
static int [] matrix = new int [10];
static Scanner input = new Scanner(System.in);
public static void main(String[] args) throws IOException
{
String fileName = "Integers.txt";
// read the file
readFile(fileName);
// print the matrix
printArray(fileName, matrix);
}
// Read File
public static void readFile(String fileName) throws IOException
{
String line = "";
FileInputStream inputStream = new FileInputStream(fileName);
Scanner scanner = new Scanner(inputStream);
DataInputStream in = new DataInputStream(inputStream);
BufferedReader bf = new BufferedReader(new InputStreamReader(in));
int lineCount = 0;
String[] numbers;
while ((line = bf.readLine()) != null)
{
numbers = line.split(" ");
for (int i = 0; i < 10; i++)
{
matrix[lineCount][i] = Integer.parseInt(numbers[i]);
}
lineCount++;
}
bf.close();
}
public static void printToFile(String fileName, String output) throws IOException
{
java.io.File file = new java.io.File(fileName);
try (PrintWriter writer = new PrintWriter(file))
{
writer.print(output);
}
}
public static void printArray(String fileName, int [] array)
{
System.out.println("The matrix is:");
for (int i = 0; i < 10; i++)
{
System.out.println();
}
System.out.println();
}
}
가 제대로 오류 메시지를 읽을 수 매트릭스를 원 추측 :은 행 번호가 있습니다. 이것은 오류가 발생한 행입니다. –
"나에게 오류를주고있다": 누가? 어디에? 어떤 예외입니까? – Viruzzo