import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class ShraniArray { public static void write (String filename, int[][]x) throws IOException{ BufferedWriter outputWriter = null; outputWriter = new BufferedWriter(new FileWriter(filename)); outputWriter.write(x.length + " " + x[0].length); outputWriter.write("\n"); for (int i = 0; i < x.length; i++) { for (int j = 0; j < x[i].length; j++) { // Maybe: outputWriter.write(x[i][j]+""); outputWriter.newLine(); } } outputWriter.flush(); outputWriter.close(); } public static int[][] read (String filename) throws IOException{ BufferedReader inReader = null; inReader = new BufferedReader(new FileReader(filename)); String tmp = inReader.readLine(); String strTmp[] = tmp.split(" "); int x = Integer.parseInt(strTmp[0]); int y = Integer.parseInt(strTmp[1]); int rez[][] = new int[x][y]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { rez[i][j] = Integer.parseInt(inReader.readLine()); } } inReader.close(); return(rez); } public static void main(String[] args) { // TODO Auto-generated method stub int [][] stevila = {{1,1,1},{2,2,2}}; try{ write("banana.txt", stevila); } catch(Exception e){ //jeba } int [][] stevila1; try { stevila1 = read("banana.txt"); for (int i = 0; i < stevila1.length; i++) { for (int j = 0; j < stevila1[i].length; j++) { System.out.print(stevila1[i][j]); } System.out.println(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }