Java Programming Assignment: File Management System

Verified

Added on  2021/12/15

|5
|1324
|177
Practical Assignment
AI Summary
This Java project implements a file management system with various functionalities. The program presents a menu-driven interface allowing users to perform several operations, including displaying the contents of a specific file, displaying the contents of a file table (listing files in a directory), displaying disk space details (total, usable, and free space), displaying disk block information, copying a file from a simulated environment to a real system, copying a file from a real system to a simulated environment, and deleting a file. The code utilizes Java's built-in libraries for file input/output, file system interaction, and user input. The program handles potential exceptions like file not found errors and input/output errors, ensuring robustness. The project demonstrates practical application of file handling concepts in Java programming.
tabler-icon-diamond-filled.svg

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
import java.io.*;
import java.util.*;
import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import javax.swing.filechooser.*;
import java.nio.file.Files;
import java.nio.file.*;
class Project
{
void DisplayFile()
{
System.out.println("Welcome to Display File Section");
String arr[]={};
InputStream istream;
OutputStream ostream;
int c;
final int EOF = -1;
ostream = System.out;
try {
File inputFile = new File("File.txt");
istream = new FileInputStream(inputFile);
try {
while ((c = istream.read()) != EOF)
ostream.write(c);
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
Project.main(arr);
} finally {
try {
istream.close();
ostream.close();
} catch (IOException e) {
System.out.println("File did not close");
Project.main(arr);
}
Project.main(arr);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
Project.main(arr);
}
Project.main(arr);
}
void DisplayFileTable()
{
System.out.println("Welcome to Display File Table Section");
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
String dirPath = "D:/As Freelancer/Live Assignment/Manjula letter and
Contents/31.Java Programming(Dec 30,2018)";
File dir = new File(dirPath);
String[] files = dir.list();
if (files.length == 0) {
System.out.println("The directory is empty");
} else {
for (String aFile : files) {
System.out.println(aFile);
}
}
String arr[]={};
Project.main(arr);
}
void DiskSpaceDetails()
{
System.out.println("Welcome to Free Space Display Section");
File file = new File("c:");
long totalSpace = file.getTotalSpace(); //total disk space in bytes.
long usableSpace = file.getUsableSpace(); ///unallocated / free disk space in
bytes.
long freeSpace = file.getFreeSpace(); //unallocated / free disk space in bytes.
System.out.println(Long.toBinaryString(totalSpace));
System.out.println(Long.toBinaryString(usableSpace));
System.out.println(Long.toBinaryString(freeSpace));
String arr[]={};
Project.main(arr);
}
void DiscBlock()
{
System.out.println("Welcome to Display Disc Block Section");
System.out.println("File system roots returned by
FileSystemView.getFileSystemView():");
FileSystemView fsv = FileSystemView.getFileSystemView();
File[] roots = fsv.getRoots();
for (int i = 0; i < roots.length; i++)
{
System.out.println("Root: " + roots[i]);
}
System.out.println("Home directory: " + fsv.getHomeDirectory());
System.out.println("File system roots returned by File.listRoots():");
File[] f = File.listRoots();
for (int i = 0; i < f.length; i++)
{
System.out.println("Drive: " + f[i]);
System.out.println("Display name: " + fsv.getSystemDisplayName(f[i]));
System.out.println("Is drive: " + fsv.isDrive(f[i]));
Document Page
System.out.println("Is floppy: " + fsv.isFloppyDrive(f[i]));
System.out.println("Readable: " + f[i].canRead());
System.out.println("Writable: " + f[i].canWrite());
System.out.println("Total space: " + f[i].getTotalSpace());
System.out.println("Usable space: " + f[i].getUsableSpace());
}
String arr[]={};
Project.main(arr);
}
void SimToReal()
{
System.out.println("Welcome to Copy a file from Sim to Real Section");
try{
Path temp = Files.move
(Paths.get("D:\\As Freelancer\\Live Assignment\\Manjula letter and Contents\\
31.Java Programming(Dec 30,2018)\\File.txt"),
Paths.get("D:\\As Freelancer\\Live Assignment\\Manjula letter and Contents\\
31.Java Programming(Dec 30,2018)\\Work\\File1.txt"));
if(temp != null)
{
System.out.println("File renamed and moved successfully");
}
else
{
System.out.println("Failed to move the file");
}
}
catch(Exception e)
{
System.out.println("Problem in File System");
}
String arr[]={};
Project.main(arr);
}
void RealToSim()
{
System.out.println("Welcome to Copy a file from Real to Sim Section");
try{
Path temp = Files.move
(Paths.get("D:\\As Freelancer\\Live Assignment\\Manjula letter and Contents\\
31.Java Programming(Dec 30,2018)\\Work\\File1.txt"),
Paths.get("D:\\As Freelancer\\Live Assignment\\Manjula letter and Contents\\
31.Java Programming(Dec 30,2018)\\File.txt"));
if(temp != null)
{
System.out.println("File renamed and moved successfully");
}
else
Document Page
{
System.out.println("Failed to move the file");
}
}
catch(Exception e)
{
System.out.println("Problem in File System");
}
String arr[]={};
Project.main(arr);
}
void DeteleFile()
{
System.out.println("Welcome to Delete File Section");
File file = new File("D:\\As Freelancer\\Live Assignment\\Manjula letter
and Contents\\31.Java Programming(Dec 30,2018)\\Work\\File1.txt");
if(file.delete())
{
System.out.println("File deleted successfully");
}
else
{
System.out.println("Failed to delete the file");
}
String arr[]={};
Project.main(arr);
}
public static void main(String[] args)
{
Project p=new Project();
Scanner sc=new Scanner(System.in);
System.out.println("\nWelcome to File Management");
System.out.println("1. Display a file");
System.out.println("2. Display the file table");
System.out.println("3. Display the free space bitmap");
System.out.println("4. Display a disk block");
System.out.println("5. Copy a file from the simulation to a file on the
real system");
System.out.println("6. Copy a file from the real system to a file in the
simulation");
System.out.println("7. Delete a file");
System.out.println("8. Exit\n");
System.out.println("Please Enter your Choice: ");
int ch=sc.nextInt();
if(ch==1)
{
p.DisplayFile();
}
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
else if(ch==2)
{
p.DisplayFileTable();
}
else if(ch==3)
{
p.DiskSpaceDetails();
}
else if(ch==4)
{
p.DiscBlock();
}
else if(ch==5)
{
p.SimToReal();
}
else if(ch==6)
{
p.RealToSim();
}
else if(ch==7)
{
p.DeteleFile();
}
else if(ch==8)
{
System.exit(0);
}
else
{
System.out.println("Wrong Input!!");
String arr[]={};
Project.main(arr);
}
}
}
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
logo.png

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]