-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.java
64 lines (63 loc) · 2 KB
/
file.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.io.*;
import java.util.*;
import java.lang.*;
import java.awt.Color;
public class file
{
public static particle[] load(String fileName)
{
particle[] particles = new particle[1000];
try
{
FileReader fr = new FileReader(fileName);
BufferedReader br = new BufferedReader(fr);
String line = br.readLine();
int i = 0;
while(line != null)
{
Scanner sc = new Scanner(line);
sc.useDelimiter(",");
particles[i] = new particle(sc.nextDouble(),sc.nextDouble(),sc.nextDouble(),sc.nextDouble(),sc.nextDouble(),sc.nextDouble(),Color.RED);
Color tempColor = new Color(sc.nextInt(),sc.nextInt(),sc.nextInt());
particles[i].color = tempColor;
line = br.readLine();
i++;
}
fr.close();
}
catch(Exception e)
{
System.out.println("Error: " + e);
}
int particlesSize = 0;
while(particles[particlesSize] != null)
{
particlesSize++;
}
particle[] particlesTemp = new particle[particlesSize];
for(int j = 0;j < particlesSize;j++)
{
particlesTemp[j] = particles[j];
}
particles = particlesTemp;
return particles;
}
public static void save(String fileName,particle[] particles)
{
try
{
FileWriter fw = new FileWriter(fileName);
BufferedWriter bw = new BufferedWriter(fw);
for(int i = 0;i < particles.length;i++)
{
particle tp = particles[i];
fw.write(tp.x + "," + tp.y + "," + tp.vx + "," + tp.vy + "," + tp.mu + "," + tp.r + "," + tp.color.getRed() + "," + tp.color.getGreen() + "," + tp.color.getBlue());
}
fw.close();
}
catch(Exception e)
{
System.out.println("Error: " + e);
}
}
}