0
所以我试图从文本文件中读取字节,然后读取它的字符。 但我试图将它插入到二维数组,这是ankoshh。将文件读入二维数组?
任何帮助表示赞赏:)
public class SteamOutputToFile
{
public static void main(String [] args)
{
int row;
int col;
String [][] ankoshh = new String[row][col];
try{
InputStream inputstream = new FileInputStream("E:\\testing.txt");
int data = inputstream.read();
while(data != -1) {
//do something with data...
System.out.print((char)data);
data = inputstream.read();
}
}
catch (IOException ioexception){
System.out.println("File input error occured!");
ioexception.printStackTrace();
}
for (int i=0; i<ankoshh.length;i++)
{
for (int j=0; j<ankoshh[i].length;j++)
{
ankoshh[row][col] = (char)data[i];
}
数据被用作两个阵列和在代码诠释。这是什么?您可以使用InputStream.read将文件读取到字节数组。你知道在你的例子中ankoshh实际上是三维吗? – Basilevs 2014-10-03 02:42:21
你也使用'ankoshh'好像它是一个char [] []',但它被声明为String [] []'。此外,你似乎完全不清楚你想达到什么目的。一个文件没有二维数组的自然表示。数据应该放在哪里? – 5gon12eder 2014-10-03 02:45:34
@ 5gon12eder,他有预先分配的数组,所以可能尺寸大小是已知的。 – Basilevs 2014-10-03 02:46:54