您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)


Content Index

Content Page # 16

What is a file?

Examples of files include the text files that are your Java source files, documents storing word processor pages, databases, numerical tables and charts from spreadsheet applications. Files can store any type of data, in any format. To the computer a file is simply a heap of bytes.

Note: Any structure in the file is put there by the programmer.

The most important thing that a Java application can do, that an applet cannot, is to read and write files on the user’s computer. Almost all computer applications manipulate files. You will probably have realised by now, that any data stored in the variables of a Java program are lost when the program finishes. The use of files is the simplest way to store the data that a program works on.

If you use a computer for ordinary applications, then you probably have a mental model of a ‘file’ already. The problem that many novice programmers face is that their mental models of files do not correspond at all with the way that the program ‘sees’ a file. User interfaces like those provided with Microsoft Windows have encouraged us to see files as documents and folders; but to the programmer a file is simply a heap of bytes.

 

There is no intrinsic structure to files . If a file has a particular meaning, e.g., it is a word processor document, it is because the programmer defined it to be that way.

Note also that Microsoft Windows has a convention of using ‘file extensions’ (.txt, .exe, .html, .java etc.) to represent the contents of files. This is merely a convention . The content of a file is specified in the program that writes it.

Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg