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;
- /**
- *
- * @author grahg
- */
- public class JavaApplication1 {
- public static void array_to_csv() throws IOException
- {
- // PRVNI
- int velX = 10;
- int velY = 10;
- double [][]matice = new double[velX][velY];
- String csv = velX + "," + velY + ",\n";
- for (int i=0; i<velX; ++i) {
- for (int j=0; j<velY; ++j) {
- matice[i][j]= (double)Math.random() + (double)Math.random() * 1000;
- csv = csv + matice[i][j] + ",";
- }
- csv = csv + "\n";
- }
- File file = new File("/home/grahg/a.csv");
- if (!file.exists())
- file.createNewFile();
- else if (file.canRead()) {
- FileWriter fw = new FileWriter(file.getAbsoluteFile());
- BufferedWriter bw = new BufferedWriter(fw);
- bw.write(csv);
- bw.close();
- }
- }
- public static void print_csv() throws IOException
- {
- // DRUHY
- BufferedReader br = new BufferedReader(new FileReader("/home/grahg/a.csv"));
- String line;
- line = br.readLine();
- String[] parts = line.split(",");
- int x = Integer.parseInt(parts[0]);
- int y = Integer.parseInt(parts[1]);
- double [][]matice2 = new double[x][y];
- for (int i=0; i<y; ++i) {
- if ( (line = br.readLine() ) == null) break;
- String[] values = line.split(",");
- for (int j=0; j<y; ++j) {
- matice2[i][j]= Float.parseFloat(values[j]);
- System.out.print(matice2[i][j] + ",");
- }
- System.out.println();
- }
- br.close();
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException {
- array_to_csv();
- //print_csv();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement