Hi
I am working on a personal project for a friend of mine.The requirement is to display the data fetched from a hand held device namely the product barcode and the quantity.I have followed the manufacturers guide and have flashed the device with a sample program that records the barcode and the quantity.After recording the data and transferring the file over to the PC, the data in the file is not very legible. After looking around I could figure out that the data was corresponding to the barcode(which is fairly easy to figure out ) and the quantity which after a lot of searching around made me realise was the hexadecimal eqivalent of the decimal quantity entered.I have tried the File Reader and the Buffered Reader but to no avail. My guess is that each record (i.e the barcode and the corresponding quantity) take up 64 and 8 bits respectively.I was wondering if someone would be kind enough to direct me to print the values of the barcode and the quantity to a file(ideally CSV) using Java please.I am attaching a sample of the datafile which needs to be parsed.The numbers found in the file are the barcodes and the illegible data are their corresponding quantities 10,80 n 100 respectively.Any pointer in the right direction would be greatly appreciated.

Regards
Kalz

Can you post the data here on the forum with comments about what it is suppose to contain and what you want done with the data when it is read from the file.

For example:
The data on each line contains the dasdfasf in columns 1-40 and the rwrwrf in columns 41-90.
There are 2342 lines of data, each has a unique dasdfasf value.

and some of your java code would come in handy, too

Hi and thanks for getting back.Sorry I was away for a while and could not reply to the thread.This is the basic code that I have got in place.Please find the data file which has to be read as an attachment.The Hand held device is Dr.Dos based and is coded in C.I am not very great at coding in C,I am comfortable coding in Java.This datafile is actually a collection of barcodes and their corresponding quantity entries on the hand held device transferred over to a PC through a bat file.I would like to read the product data and the corresponding barcode and write it out to a CSV .I have managed to read the first two products and their respective barcodes but could not figure out where I am going wrong as I could not get the third barcode in the datout.txt file. Any help in this regard would be greatly appreciated.

package JApp;
import java.util.*;
import java.io.*;
 

class Japp{
    public static void main(String args[])
    {
       try{
   // Open the file
   FileInputStream fstream = new FileInputStream("C:\\Users\\kalyan\\Desktop\\dataout.txt");
   // Get the object of DataInputStream
   DataInputStream in = new DataInputStream(fstream);
   BufferedReader br = new BufferedReader(new InputStreamReader(in));
   String strLine;
   int n=1;
   File file = new File("C://Users//kalyan//Desktop/dataout.txt");
   RandomAccessFile raf = new RandomAccessFile(file, "r");
   byte [] b =new byte[1];
   System.out.println("Barcode \t\t  Quantity");
    
  while ((strLine = br.readLine()) != null)   
           {
   
   // Seek to the location of quantity 64,64*2+2,64*3+4 and so on
   raf.seek((64*n)+2*(n-1));
   byte ch = raf.readByte();
   System.out.println(strLine.substring(0,32)+ (int)ch);
   //raf.close();
   n++;
   }
   //Close the input stream
   in.close();
   }catch (Exception e)
       
   {//Catch exception if any
   System.err.println("Error: " + e.getMessage());
   }
   }
}

Can you define char by char what is in the DATAOUT.txt file?
I see some numbers and some spaces???

Hi!
The file contains the product barcodes and their quantities.The file posted has three products whose barcodes are 9556111603667, 9556111603711 and 50309511 with their quantities 10, 100 and 80 respectively.When I happened to open up the file in notepad c++ I could makeout that the file started with the barcodes followed by nulls till the quantity value at the 64th position (in ascii format)followed by a null and the same format again.The program posted above, prints the barcode and the quantity for two products.But it fails to print the third product and its barcode.I am not able to understand where I am going wrong.The hand held device used to record the info uses c programming and linked lists to write to the file.If it would help I can post the source code for the C program in here.
Thanks
Kalz

Can you define char by char what is in the DATAOUT.txt file?
For example:
1-20 = barcode digits
21-63 = spaces
64 = code
65-99 = some more stuff
100-122 = and more stuff
etc up to the last byte of the file

Hi NormR1.Thanks for getting back.Sorry for taking ages to reply.
The file starts with the barcode first 13 digits followed by spaces till the 63 digit the 64digit contains the quantity in ascii format followed by a space at the 65 digit the 2nd barcode 13 digits from 66 till 78 and blank spaces till the 129 digit, 2nd quantity at the 130 digit followed by a space ,3rd barcode 7 digits from 132 till 139 followed by blank spaces till 195 the 196 digit contains the third quantity in ascii format followed by a space and the file ends.Hope it helps.

Did you see how I posted the layout? In columns that are easy to read.
Please edit your post and put the layout in columns.
First column is the location.
Second column is the contents

Yeah sure
1-13 = first barcode digits
14-63 = spaces
64 = quantity code
65 = space
66-78=2nd barcode
79-129=blank spaces
130=2nd product quantity
131=space
132-139=3rd barcode
140-195=spaces
196=3rd product quantity
197=space
198=end of file

Interesting that the first 2 barcodes are 13 digits long and the 3rd one is 8

If you read the record into a String, you can use the substring() method to get each of the fields. Something like this:

String firstBC = record.substring(0, 13);
int firstQC = (int)record.charAt(63);  
String secBC = record.substring(65, 77);
int secQC = (int)record.charAt(129);
String thirdBC  = record.substring(131, 138);
int thirdQC = (int)record.charAt(195);

This may take some tuning of indexes but this is the general idea

Thanks for the input.I will work on it and post if there is any problems.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.