2
我需要從定時間隔的4個單獨.csv
數據文件中提取數據以同時輸出數字。我只能得到文件順序拉。我不確定線程是否會有所幫助,我從來沒有能夠讓它們正常運行。我的最終結果將在JFrame
中顯示輸出。同時讀取.csv文件
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class Inputtest {
public static void main(String[] args) throws IOException, InterruptedException {
O21 a = new O21();
O22 b = new O22();
PH1 c = new PH1();
PH2 d = new PH2();
a.O21();
b.O22();
c.PH1();
d.PH2();
}
}
class O21
{
public void O21() throws FileNotFoundException, InterruptedException {
int e = 21; //preset Level
Scanner O1 = new Scanner(new File("O21.txt"));
O1.useDelimiter(",");
while (O1.hasNext()) {
String a = O1.next();
int aa = Integer.parseInt(a);
Thread.sleep(500); // Time delay for output
if (a.trim().isEmpty()) { continue; }
if(aa > (e + 1)) {
System.out.println(a);
System.out.println("Alarm high");
continue;
}
if(aa < (e-1)) {
System.out.println(a);
System.out.println("Alarm Low");
continue;
}
System.out.println(a);
}
}
}
class O22 {
public void O22() throws FileNotFoundException, InterruptedException {
double f = 20; //preset Level
Scanner O2 = new Scanner(new File("O22.txt"));
O2.useDelimiter(",");
while (O2.hasNext()) {
String b = O2.next();
int bb = Integer.parseInt(b);
Thread.sleep(500); // Time delay for output
if (b.trim().isEmpty()) { continue; }
if(bb > (f + 1)) {
System.out.println(b);
System.out.println("Alarm high");
continue;
}
if (bb < (f - 1)) {
System.out.println(b);
System.out.println("Alarm Low");
continue;
}
System.out.println(b);
}
}
}
class PH1 {
public void PH1() throws FileNotFoundException, InterruptedException {
double g = 7; //preset Level
Scanner P1 = new Scanner(new File("PH1.txt"));
P1.useDelimiter(",");
while (P1.hasNext()) {
String c = P1.next();
double cc = Double.parseDouble(c);
Thread.sleep(1000); // Time delay for output
if (c.trim().isEmpty()) { continue; }
if (cc > (g + .5)) {
System.out.println(c);
System.out.println("Alarm high");
continue;
}
if (cc < (g - .5)) {
System.out.println(c);
System.out.println("Alarm Low");
continue;
}
System.out.println(c);
}
}
}
class PH2 {
public void PH2() throws FileNotFoundException, InterruptedException {
double h = 7; //preset Level
Scanner P2 = new Scanner(new File("PH2.txt"));
P2.useDelimiter(",");
while (P2.hasNext()) {
String d = P2.next();
double dd = Double.parseDouble(d);
Thread.sleep(1000); // Time delay for output
if (d.trim().isEmpty()) { continue; }
if (dd > (h + .5)) {
System.out.println(d);
System.out.println("Alarm high");
continue;
}
if (dd < (h - .5)) {
System.out.println(d);
System.out.println("Alarm Low");
continue;
}
System.out.println(d);
}
}
}