Page 359 - Cs_withBlue_J_C11_Flipbook
P. 359

42              ob.read();
                  43              ob.printlong();

                  44          }
                  45      }
                 The output of the preceding program is as follows:

                 Enter a sentence
                 Saturn, Mars, and Earth are planets in our solar system.
                 Longest word is
                 planets

                 If more than one word has the highest length, which means two or more words have the same length, then the
                 preceding program would return all the words having the highest length.


                     12.3 DATA FILE HANDLING
                 Till  now,  we  have  used variables to store  values.  These values gets lost when a program’s execution  is stopped.
                 Sometimes, we face a situation in which we need to store a value or several values permanently for future reference.
                 For example, when an employee joins a particular organisation, the organisation collects data about the employee like
                 name, father’s name, mother’s name, date of birth, gender, etc. and stores this data in the organisation’s information
                 system permanently. Similarly, organisation has collected data of thousands of employees. So, to handle large amounts
                 of data, Java provides the concept of files. The process of handling files is called file handling.
                 A file is a named location that can be used to store related data permanently in a secondary storage device. Files are
                 stored in an organised manner in directories. There are different types of files and formats available on computers as
                 described in the following table.

                                     File Type                                    Description
                        Image files                          These files store images or graphics. Image files can be of different
                                                             types namely .jpeg, .gif, .png, .tif, .svg, etc.
                        Document files                       These files are used to create, edit and print documents. There are
                                                             different types of document files like .doc, .pdf, .txt, etc.
                        Video files                          These files are stored in file formats like .mp4, .avi, .mov, .flv, etc.

                        Audio files                          These files are used to store songs, lectures, etc. in different audio
                                                             file formats like .mp3, .wav, etc.
                        Database files                       These files store related records in an organised manner. There are
                                                             various types of database files like .mdb, .csv, .xls, .sql, .idx, etc.
                        Program files                        These files are used to store code written in different programming
                                                             languages. There are different types of  program files  like .java,
                                                             .bas, .cpp, .py, etc.

                 Data files are the files that contain data in the form of records. A record is further divided into fields. Data files are
                 non-executable files that can be created, read or viewed. In some data files, data is stored in the form of text but some
                 other data files store data in a more organised manner as records. The different subdivisions are:
                 •  Field: It is the smallest unit of data that can be accessed by a user. It is identified by a unique name called field name.

                 •  Record: It is a collection of related fields.
                 •  File: Files (data files) are a collection of related records.



                                                                                                                       357
                                                                                 Basic Input/Output and Data File Handling    357
   354   355   356   357   358   359   360   361   362   363   364