【发布时间】:2015-10-08 16:54:04
【问题描述】:
如何将二维字符数组写入文件。我到处寻找解决方案,但没有找到答案。
void printDATA(){
String[][] stringArray = Arrays.copyOf(data, data.length, String[][].class);
char[][] charArray = new char[stringArray.length][stringArray[0].length];
for(int i = 0; i < stringArray.length; i++)
{
for(int j = 0; j < stringArray[0].length; j++)
{
charArray[i][j] = stringArray[i][j].charAt(0);
}
}
File file = new File("result.doc");
try {
//FileWriter fout = new FileWriter(file);//Gives error
PrintWriter fout = new PrintWriter(file);//This also gives error
fout.write(charArray);
fout.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
【问题讨论】: