Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication1;
  7.  
  8. import java.io.*;
  9. import java.util.ArrayList;
  10. import java.util.Scanner;
  11.  
  12.  
  13.  
  14. /**
  15.  *
  16.  * @author grahg
  17.  */
  18. public class JavaApplication1 {
  19.  
  20.     /**
  21.      * @param args the command line arguments
  22.      */
  23.     public static void main(String[] args) throws IOException {
  24.         // PRVNI
  25.         float [][]matice = new float[10][10];
  26.         for (int i=0;i<10;++i)
  27.             for (int j=0;j<10;++j)
  28.                 matice[i][j]=(float) Math.random();
  29.            
  30.            String csv = "10,10,\n";
  31.            
  32.            
  33.            
  34.            for (int i=0;i<10;++i){
  35.                for (int j=0;j<10;++j) {
  36.                    csv = csv + matice[i][j] + ",";
  37.                }
  38.                csv = csv + "\n";
  39.            }
  40.            
  41.         File file = new File("/home/grahg/filename.txt");
  42.  
  43.             // if file doesnt exists, then create it
  44.     if (!file.exists()) {
  45.             file.createNewFile();
  46.         }
  47.  
  48.     FileWriter fw = new FileWriter(file.getAbsoluteFile());
  49.         BufferedWriter bw = new BufferedWriter(fw);
  50.     bw.write(csv);
  51.     bw.close();
  52.      
  53.        
  54.        
  55.        
  56.         // DRUHY
  57.         BufferedReader br = new BufferedReader(new FileReader("/home/grahg/filename.txt"));
  58.         String line;
  59.        
  60.         line = br.readLine();
  61.         String[] parts = line.split(",");
  62.         int x = Integer.parseInt(parts[0]);
  63.         int y = Integer.parseInt(parts[1]);
  64.        
  65.         float [][]matice2 = new float[x][y];
  66.        
  67.         int i=0;
  68.         while ((line = br.readLine()) != null) {
  69.              String[] values = line.split(",");
  70.            
  71.              for (int j=0; j<y; ++j)
  72.              {
  73.                  matice2[i][j]= Float.parseFloat(values[j]);
  74.              }
  75.              ++i;
  76.     }
  77.        
  78.         /*
  79.          
  80.            for (int xx=0;xx<10;++xx){
  81.                for (int yy=0;yy<10;yy++) {
  82.                    System.out.println(matice2[xx][yy] + ",");
  83.                }
  84.                System.out.println("\n");
  85.            }
  86.    
  87.            */
  88.     }
  89.    
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement