473,659 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading trailer from .dat

1 New Member
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 1904

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

Similar topics

6
2399
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 Reading opens the mind to new ways of understanding Reading is fun Accordingly, I suggest the following works of literature:
1
7070
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 text file while doing the bcp? If so, how?
19
10306
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 text is available until I have read it... which seems to imply that multiple reads of the input stream will be inevitable. Now I can correctly find the number of characters available by: |
4
9823
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 = tmpfile(); /* write into tmpFile */ ...
8
9512
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 contains the following three floating-point numbers: 1.0 2.0 3.0
11
1281
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 the last line in the file and load them in 2 strings so I can compare them? Thank you. Catalin
9
5507
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 http://www.developersdex.com ***
4
3258
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 Lunch, just lunch.
4
1879
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, "siteformatting.css" The home page, "index.php" must link to the master CSS file, so that HTML elements in this file can conform to site-wide standards, right? (Or
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8850
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2749
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.