2 Replies - 5118 Views - Last Post: 20 June 2008 - 07:02 AM Rate Topic: -----

#1 tosy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-June 08

reading selected data to the screen

Posted 19 June 2008 - 06:28 AM

How can I specify the data (datetime, mote_id, rssi, Temp, humidity, tsr, par and InVolt) I want to read from a tab delimited text file, or tell the code to skip the irrelevant data. i.e I want to read and parse then remove the entry.

the code (which I got from google) and is working perfectly, i.e printing all the data in the text file to the console:

package MyProject;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * This program reads a text file line by line and print to the console. It uses
 * FileOutputStream to read the file.
 * 
 */
public class FileInput {

  public static void main(String[] args) {

	File file = new File("C:\\test.txt");
	FileInputStream fis = null;
	BufferedInputStream bis = null;
	DataInputStream dis = null;

	try {
	  fis = new FileInputStream(file);

	  // Here BufferedInputStream is added for fast reading.
	  bis = new BufferedInputStream(fis);
	  dis = new DataInputStream(bis);

	  // dis.available() returns 0 if the file does not have more lines.
	  while (dis.available() != 0) {

	  // this statement reads the line from the file and print it to
		// the console.
		System.out.println(dis.readLine());
	  }

	  // dispose all the resources after using them.
	  fis.close();
	  bis.close();
	  dis.close();

	} catch (FileNotFoundException e) {
	  e.printStackTrace();
	} catch (IOException e) {
	  e.printStackTrace();
	}
  }
}




An example of what is contained in the .txt file;
Wed Jun 18 13:34:11 BST 2008 00 FF FF 00 08 10 00 0A FF E3 00 00 00 34 18 54 06 46 01 35 00 B1 0F FF mote_id:8.00 RSSI:-29 Temp:22.68 Humidity:-374.43 Tsr:87.02 Par:405.12 InVolt:2.00
Wed Jun 18 13:34:12 BST 2008 00 FF FF 00 03 12 00 0F 00 00 00 03 00 00 00 32 18 0A 06 EB 02 C8 01 56 0F 95 mote_id:3.00 RSSI:-65536 Temp:-39.10 Humidity:-1389.67 Tsr:498.74 Par:1629.64 InVolt:0.00
Wed Jun 18 13:34:13 BST 2008 00 FF FF 00 08 10 00 0A FF E3 00 00 00 35 18 53 06 48 01 42 00 C0 0F FB mote_id:8.00 RSSI:-29 Temp:22.67 Humidity:-374.85 Tsr:90.68 Par:439.45 InVolt:2.00
Wed Jun 18 13:34:16 BST 2008 00 FF FF 00 08 10 00 0A FF E4 00 00 00 36 18 50 06 54 01 5E 00 D6 0F FF mote_id:8.00 RSSI:-28 Temp:22.64 Humidity:-377.38 Tsr:98.57 Par:489.81 InVolt:2.00

All help greatly appreciated.
Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: reading selected data to the screen

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: reading selected data to the screen

Posted 19 June 2008 - 03:38 PM

dis.readLine() returns a String so
String str = dis.readLine();
have a look at the class StringTokenizer it will allow you to iterate throw all the "tokens" in a String
tokens being elements separated by a delimiter
Was This Post Helpful? 0
  • +
  • -

#3 tosy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-June 08

Re: reading selected data to the screen

Posted 20 June 2008 - 07:02 AM

View Postpbl, on 19 Jun, 2008 - 03:38 PM, said:

dis.readLine() returns a String so
String str = dis.readLine();
have a look at the class StringTokenizer it will allow you to iterate throw all the "tokens" in a String
tokens being elements separated by a delimiter






Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1