0% found this document useful (0 votes)
2 views

file handling and file operations in java

The document discusses file handling and operations, highlighting the importance of managing data in programming. It explains various file operations in Python, including opening, reading, writing, and closing files, along with their modes. Additionally, it outlines practical applications of file handling in real-world scenarios such as data storage, user settings, and multimedia management.

Uploaded by

pr6660270
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

file handling and file operations in java

The document discusses file handling and operations, highlighting the importance of managing data in programming. It explains various file operations in Python, including opening, reading, writing, and closing files, along with their modes. Additionally, it outlines practical applications of file handling in real-world scenarios such as data storage, user settings, and multimedia management.

Uploaded by

pr6660270
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

AURORA DEEMED TO BE

UNIVERSITY

FILE HANDLING AND FILE OPERATIONS

Presented By – Course Instructor –


G Siddhartha - AUU23EGCSA011 Mrs. M. Swapna
Sai Ruthvik - AUU23EGCSA020 HOD of Dept of AIML&DS
P Vishnu Vardhan- AUU23EGCSA002 Aurora Deemed To Be University
2

FILE HANDLING AND FILE OPERATIONS


3
AGENDA

FILE HANDLING

FILE OPERATIONS

LIST OF FILE OPERATIONS

CODING

APPLICATIONS

CONCLUSION
4

FILE HANDLING
5

FILE HANDLING
File handling in programming refers to the process of creating,
opening, reading, writing, and closing files. It allows us to store
and manage data outside of the program, so information can
be saved and accessed later. This is useful for tasks like saving
user data, logs, and settings.
6

FILE OPERATIONS
FILE OPERATIONS 7

The key function for working with files in Python is the open() function.
The open() function takes two parameters; filename, and mode.
There are four different methods (modes) for opening a file:

"r" - Read - Default value. Opens a file for reading, error if the file does not exist
"a" - Append - Opens a file for appending, creates the file if it does not exist
"w" - Write - Opens a file for writing, creates the file if it does not exist
"x" - Create - Creates the specified file, returns an error if the file exists

In addition, we can specify if the file should be handled as binary or text mode

"t" - Text - Default value. Text mode


"b" - Binary - Binary mode (e.g. images)
Operation Method/Function Description
Opening a File open(filename, mode) Opens a file in the specified mode.

8
Reading Entire File file.read() Reads the entire content of the file.

Reading Line by Line file.readline() Reads one line from the file at a time.

Reading All Lines file.readlines() Reads all lines and returns them as a list.

Writing to a File file.write(data) Writes data (string) to the file.

Writing Multiple Lines file.writelines(list_of_strings) Writes a list of strings to the file.

Closing a File file.close() Closes the file.


Automatic Closing with open(filename, mode) as file Opens a file and closes it automatically after use.

Moving Cursor file.seek(offset, whence) Moves the cursor to a specified position.

Getting Cursor Position file.tell() Returns the current position of the file cursor.

Check File Existence os.path.exists(filename) Checks if a file exists in the directory.

Deleting a File os.remove(filename) Deletes the specified file.


Renaming a File os.rename(old_name, new_name) Renames a file from old_name to new_name.
9

CODE
10
11
12
13
14
15
16
17
18
19

APPLICATIONS
20
• Saving Data: Apps store user information, like saved games or documents.
• Settings Storage: Programs use files to remember user settings.
• Logs: Systems keep logs to track errors or activities.
• Data Sharing: Files like CSV or JSON make it easy to share data between apps.
• Backups: Important files are saved as backups in case of data loss.
• Multimedia: Media files are handled to view, edit, or play content.
• Databases: Databases use files to store information and for exporting data.
• User Authentication: Files can securely store login details.
• Reports: Systems create reports as text or PDF files for users.
• Websites: Websites rely on files for HTML, CSS, and images.
21
CONCLUSION
file handling and operations are essential in managing and
storing data effectively in real-world applications. They allow
programs to save, retrieve, and share information, making
them crucial for everything from data storage and user
settings to log management and multimedia handling.
Mastering file handling is a valuable skill that enhances
application functionality and ensures data is used efficiently.
22

You might also like