Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- import java.io.*;
- import java.util.ArrayList;
- import java.util.Scanner;
- /**
- *
- * @author grahg
- */
- public class JavaApplication1 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException {
- // PRVNI
- float [][]matice = new float[10][10];
- for (int i=0;i<10;++i)
- for (int j=0;j<10;++j)
- matice[i][j]=(float) Math.random();
- String csv = "10,10,\n";
- for (int i=0;i<10;++i){
- for (int j=0;j<10;++j) {
- csv = csv + matice[i][j] + ",";
- }
- csv = csv + "\n";
- }
- File file = new File("/home/grahg/filename.txt");
- // if file doesnt exists, then create it
- if (!file.exists()) {
- file.createNewFile();
- }
- FileWriter fw = new FileWriter(file.getAbsoluteFile());
- BufferedWriter bw = new BufferedWriter(fw);
- bw.write(csv);
- bw.close();
- // DRUHY
- BufferedReader br = new BufferedReader(new FileReader("/home/grahg/filename.txt"));
- String line;
- line = br.readLine();
- String[] parts = line.split(",");
- int x = Integer.parseInt(parts[0]);
- int y = Integer.parseInt(parts[1]);
- float [][]matice2 = new float[x][y];
- int i=0;
- while ((line = br.readLine()) != null) {
- String[] values = line.split(",");
- for (int j=0; j<y; ++j)
- {
- matice2[i][j]= Float.parseFloat(values[j]);
- }
- ++i;
- }
- /*
- for (int xx=0;xx<10;++xx){
- for (int yy=0;yy<10;yy++) {
- System.out.println(matice2[xx][yy] + ",");
- }
- System.out.println("\n");
- }
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement