Code.ReadSampleDataJava History

Hide minor edits - Show changes to output

Changed lines 1-2 from:
(:source lang=Java header="This program demonstrates how to use Scanner to read SCL and raw heart data from a biosignals file." tabwidth=3 -trim :)
to:
(:source lang=Java header="This program demonstrates how to use Scanner to read SCL and raw heart data biosignals from a file." tabwidth=3 -trim :)
Added lines 1-39:
(:source lang=Java header="This program demonstrates how to use Scanner to read SCL and raw heart data from a biosignals file." tabwidth=3 -trim :)

import java.util.Scanner;
import java.io.File;

public class ReadSampleData
{
public static void main(String[] args) throws java.io.FileNotFoundException
{
// create an input scanner on the file provided as parameter to main()
Scanner data = new Scanner(new File(args[0]));

// read and output two lines
System.out.println(data.nextLine()); // read first header
System.out.println(data.nextLine()); // read second header

// extract all SCL and raw heart data from the file
while(data.hasNext()) // while there is more data
{
// there are three tokens per line (time, SCL and raw heart data)
if(!data.hasNextDouble()) // if the next token is not a double
{
String timeStamp = data.next(); // get time
System.out.print(timeStamp); // and "process" it (for now, output it)
}
else // else, read SCL and raw heart data
{
double SCL = data.nextDouble(); // read SCL data
double rawHeartData = data.nextDouble(); // read raw heart data
System.out.println(" " + SCL + " " + rawHeartData);
}
}

data.close(); // done with the scanner
}
}


(:sourcend:)