473,327 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Reading trailer from .dat

1
Well, I have to edit a program which we previously used for reading a header file to be able to read a trailer from a .dat file. The .dat file consists of 5 entries in each record and I am assuming atleast 5 records(which I believe the amount of records should be taken from the trailer). Also I believe he said the SENTINEL value must be -1.

Our instructor gave us an extremely limited amount of information on how to attempt to do this and its not in our text book and google provided no clear information on the subject that I could gather.

So if possible, could you point me in the direction of a webpage with information on this topic?

If there are no pages with relevent information, could you explain to me how I would go about editing my code below?

I bolded and underlined all areas which I believe are relevant to my problem and I also noted in certain areas using (*// ).

I would appreciate any input. I have been racking my brain for the past few hours trying to get this to work. Anyway, thank you.

.dat File(the one I have been using for testing) =
4 5 4 9 3
3 5 7 1 6
8 6 5 3 4
4 2 5 3 8
6 1 7 9 6
5

(*//I believe since I need to read a trailer file, that the # of records would be last compared to the header being first)

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileInputStream;
  4.  
  5. public class TrailerProgram
  6. {   
  7.     public static void main (String[] args)
  8.     {
  9.         final int SENTINEL = -1;
  10.          int trailer=0,i=0;   
  11.         long n1,n2,n3,n4,n5,small;
  12.         Scanner scanInput = null;     // Create a Scanner called scanInput
  13.  
  14.  
  15.  
  16.         // Data File
  17.         try
  18.         {
  19.  
  20.            scanInput = new Scanner
  21.                        (new FileInputStream ("TrailerFile.dat"));
  22.  
  23.            headings();
  24.  
  25.  
  26.  
  27.           // reading trailer
  28.           trailer = scanInput.nextInt();     (*// I am not sure how to scanInput from last value rather than from the first )
  29.          System.out.println ("\n\n\n      " + "Program Name");
  30.          System.out.println ("      " + "TRAILER VALUE IS " + trailer);
  31.          System.out.println ("\n" + "SET #       SMALLEST VALUE     INPUT VALUES FROM THE DATA FILE");
  32.  
  33.            for(i=1;i<=trailer;i++)         (*// I am not sure what he wanted the sentinel value to do at -1. )
  34.       {
  35.  
  36.                 n1 = scanInput.nextLong();
  37.                 n2 = scanInput.nextLong();
  38.                 n3 = scanInput.nextLong();
  39.                 n4 = scanInput.nextLong();
  40.                 n5 = scanInput.nextLong();
  41.  
  42.  
  43.                 small = findSmallValue ( n1, n2,n3, n4, n5);
  44.                 System.out.printf("%3d.",i);
  45.                 printValues(n1,n2,n3,n4,n5,small);   
  46.             }       
  47.  
  48.  
  49.  
  50.  
  51.          }
  52.          catch (FileNotFoundException e)
  53.          {
  54.             System.out.println ("\n\n\n\n"
  55.                     + "****  The following data file was not found.  ****");
  56.             System.out.println
  57.                     ( "****  TrailerFile.dat                 ****");
  58.  
  59.          }
  60.  
  61.     }
  62.  
  63. // ===================== findSmallValue =====================
  64.  //determine the smallest value of the four longs returned .
  65.  
  66.      public static long findSmallValue (long n1, long n2, long n3, long n4, long n5)
  67.      {    
  68.             long small = 0;
  69.  
  70.             if ((n1 <= n2) && (n1 <= n3) && (n1 <= n4) && (n1 <= n5))
  71.                  small = n1;
  72.             else if  ((n2 <= n1) && (n2 <= n3) && (n2 <= n4) && (n2 <= n5))
  73.                   small = n2;
  74.             else if  ((n3 <= n1) && (n3 <= n2) && (n3 <= n4) && (n3 <= n5))
  75.                   small = n3;
  76.             else if  ((n4 <= n1) && (n4 <= n2) && (n4 <= n3) && (n4 <= n5))
  77.                   small = n4;
  78.             else 
  79.                   small = n5;
  80.  
  81.         return small;
  82.  
  83.      } 
  84.  
  85. // ===================== printValues =====================       
  86. // 
  87.  
  88.      public static void printValues (long n1, long n2, long n3, long n4, long n5, long small)
  89.      {    
  90.  
  91.  
  92.          System.out.printf("%15d %15d %7d %5d %5d %5d\n",small,n1,n2,n3,n4,n5);
  93.  
  94.      }
  95.  
  96. }
Nov 19 '06 #1
0 1883

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Raymond Hettinger | last post by:
Found in a pamphlet at a pre-school: --------------------------------------- Reading improves vocabulary Reading raises cultural literacy through shared knowledge Reading develops writing skills...
1
by: sbh | last post by:
I'm copying data out to a file with pipe delimiters. I would like to add a header and trailer. Is this possible? If so, please help me with the steps. Also, is it possible to append to a...
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
8
by: Yeow | last post by:
hello, i was trying to use the fread function on SunOS and ran into some trouble. i made a simple test as follows: i'm trying to read in a binary file (generated from a fortran code) that...
11
by: Catalin Porancea | last post by:
Hello, I have a txt file that I need to validate before importing in a database. In order to be valid, the file needs to have a header, records and a trailer. How do I read only the first and...
9
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex...
4
by: Gaijinco | last post by:
I had a file named nap.in which looks like this: 4 10:00 12:00 Lectures 12:00 13:00 Lunch, like always. 13:00 15:00 Boring lectures... 15:30 17:45 Reading 4 10:00 12:00 Lectures 12:00 13:00...
4
by: henry | last post by:
Folks: Using Dreamweaver CS3... Consider a home page, "index.php" which conditionally REQUIREs one of 'N' HTML files of pure content. All site styles are specified in a master CSS file,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.