Skip to content

Khansa972/Text-File-Manipulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ Text File Manipulator

A Java-based console application for text file manipulation using custom-built Data Structures.
Built entirely from scratch โ€” no Java Collections Framework used.

๐Ÿ–ฅ๏ธ GUI Version available โ†’ gui-version branch โ€” Built with JavaFX, Dark/Light theme, run on Replit!


๐Ÿ“– Overview

Text File Manipulator is a Data Structures & Algorithms (DSA) project developed in Java. It provides a menu-driven console interface to perform a wide range of operations on .txt files โ€” all powered by custom implementations of Stack and Singly LinkedList, written entirely from scratch without using Java's built-in Collections Framework.

This project demonstrates how fundamental data structures can be applied to solve real-world file manipulation problems. ๐Ÿ—‚๏ธ


๐ŸŒฟ Branches

Branch Description Run On
๐Ÿ–ฅ๏ธ main Console-based version using Scanner & File I/O ๐Ÿ–ค Terminal / CMD
๐ŸŽจ gui-version JavaFX GUI with Dark/Light theme toggle ๐ŸŒ Replit / Local

โœจ Features

# Operation Description Data Structure Used
1 ๐Ÿšซ Eliminate Repeated Lines Removes all duplicate lines from the file LinkedList (contains())
2 ๐Ÿ”„ Reverse File Content Reverses the order of all lines in the file Stack (LIFO)
3 โž• Insert New Line Inserts a new line after a target keyword Stack
4 ๐Ÿ“‹ Copy Line Copies a specific line to a clipboard Stack (Clipboard)
5 ๐Ÿ“Œ Paste Line Pastes clipboard content at a specified position Stack + LinkedList
6 โœ‚๏ธ Cut Line Removes a line and stores it in clipboard Stack (Clipboard) + LinkedList
7 ๐Ÿ”ค Sort File Content Sorts lines alphabetically using Bubble Sort Array + Bubble Sort
8 ๐Ÿ”€ Merge Files Appends content of one file into another LinkedList
9 ๐Ÿšช Exit Exits the program gracefully โ€”

๐Ÿ“ Project Structure

Text-File-Manipulator/
โ”‚
โ”œโ”€โ”€ ๐ŸŒฟ main  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Console Version
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ TextFileManipulator.java   # ๐Ÿš€ Main class โ€” entry point & all operations
โ”‚   โ”‚   โ”œโ”€โ”€ LinkedList.java            # ๐Ÿ”— Custom Singly LinkedList implementation
โ”‚   โ”‚   โ””โ”€โ”€ Stack.java                 # ๐Ÿ“š Custom Stack (array-based) implementation
โ”‚   โ”œโ”€โ”€ sample.txt                     # ๐Ÿ“„ Sample text file for testing
โ”‚   โ”œโ”€โ”€ README.md                      # ๐Ÿ“– Project documentation
โ”‚   โ”œโ”€โ”€ .gitignore                     # ๐Ÿ™ˆ Git ignore rules
โ”‚   โ””โ”€โ”€ LICENSE                        # ๐Ÿ“œ MIT License
โ”‚
โ””โ”€โ”€ ๐ŸŒฟ gui-version โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ JavaFX GUI Version
    โ”œโ”€โ”€ src/
    โ”‚   โ””โ”€โ”€ TextFileManipulatorGUI.java  # ๐ŸŽจ Complete GUI โ€” single file (DSA included)
    โ”œโ”€โ”€ sample.txt                       # ๐Ÿ“„ Sample text file for testing
    โ”œโ”€โ”€ .replit                          # โ–ถ๏ธ  Replit run configuration
    โ”œโ”€โ”€ README.md                        # ๐Ÿ“– GUI version documentation
    โ”œโ”€โ”€ .gitignore                       # ๐Ÿ™ˆ Git ignore rules
    โ””โ”€โ”€ LICENSE                          # ๐Ÿ“œ MIT License

๐Ÿงฑ Data Structures Implemented

๐Ÿ”ท Stack (Array-Based)

A custom Last-In-First-Out (LIFO) data structure implemented using an array. ๐Ÿ“š

Method Description
push(String x) โฌ†๏ธ Add element to top
pop() โฌ‡๏ธ Remove and return top element
peek() ๐Ÿ‘๏ธ View top element without removing
peekindex(int index) ๐Ÿ” Access element at a specific position
stacksize() ๐Ÿ“ Get current number of elements
isEmpty() โ“ Check if stack is empty
clearstack() ๐Ÿงน Remove all elements
display() ๐Ÿ–จ๏ธ Print all elements

Used for: ๐Ÿ“‹ Clipboard (copy/cut/paste), ๐Ÿ”„ file content reversal, โž• line insertion


๐Ÿ”— Singly LinkedList

A custom dynamic linear data structure using Node-based links. ๐Ÿ”—

Method Description
addFirst(String data) โฎ๏ธ Insert at head
addLast(String data) โญ๏ธ Insert at tail
delFirst() โŒ Delete head node
deletefirstString() โœ‚๏ธ Delete and return head data
contains(String data) ๐Ÿ”Ž Search for a value
isEmpty() โ“ Check if list is empty
Size() ๐Ÿ“ Return total node count
display() ๐Ÿ–จ๏ธ Print all elements
reverseAndWriteToFile(String path) ๐Ÿ”„ Reverse file using Stack

Used for: ๐Ÿ’พ Storing file lines, ๐Ÿšซ duplicate removal, ๐Ÿ”€ file merging, โœ‚๏ธ๐Ÿ“Œ paste/cut operations


๐Ÿ“š Topics Covered

๐Ÿ—‚๏ธ Data Structures:

  • ๐Ÿ”— Singly Linked List (insertion, deletion, traversal, searching)
  • ๐Ÿ“š Stack using Array (push, pop, overflow & underflow handling)
  • ๐Ÿ—ƒ๏ธ Array (used in sorting)

โšก Algorithms:

  • ๐Ÿ”ค Bubble Sort (on String array using compareTo())
  • ๐Ÿ”Ž Linear Search (for duplicate detection via contains())
  • ๐Ÿ”„ LIFO-based reversal

โ˜• Java Concepts:

  • ๐Ÿ“‚ File I/O โ€” BufferedReader, BufferedWriter, FileReader, FileWriter, RandomAccessFile
  • ๐Ÿงฉ Object-Oriented Programming โ€” Classes, Objects, Inner Classes (Node)
  • ๐Ÿ” Recursion โ€” Used in checkname() for file validation
  • ๐Ÿ›ก๏ธ Exception Handling โ€” try-catch, IOException, NoSuchElementException
  • ๐Ÿ”  String manipulation โ€” contains(), compareTo(), equalsIgnoreCase()

โš™๏ธ How to Run โ€” Console Version

๐Ÿ“‹ Prerequisites

  • โ˜• Java JDK 8 or above
  • ๐Ÿ–ค Terminal / Command Prompt

๐Ÿชœ Steps

# Step 1: Clone the repository
git clone https://github.com/Khansa972/Text-File-Manipulator.git

# Step 2: Navigate to src folder
cd Text-File-Manipulator/src

# Step 3: Compile all Java files
javac Stack.java LinkedList.java TextFileManipulator.java

# Step 4: Run the program
java TextFileManipulator

๐Ÿงช Test with Sample File

When the program asks for a file name, enter:

sample

โš ๏ธ Make sure sample.txt is in the same folder where you run java TextFileManipulator.


๐ŸŽจ How to Run โ€” GUI Version

Switch to the gui-version branch for full instructions.

# Switch to GUI branch
git checkout gui-version

# Navigate to src
cd src

# Compile
javac TextFileManipulatorGUI.java

# Run
java TextFileManipulatorGUI

Or run directly on ๐ŸŒ Replit โ€” see the gui-version branch README for steps.


๐Ÿ–ฅ๏ธ Program Demo โ€” Console

---------------------------------------------------------------------------------
               T E X T   F I L E   M A N I P U L A T O R
---------------------------------------------------------------------------------
Enter File Name in which you want changes :
> sample

Length of File : 120

------------------------------------------------------------------
 PRESS :
(1). Eliminate repeated Lines from the file
(2). Reverse the content of file
(3). Insert new Line
(4). Copy text
(5). Paste text Line
(6). Cut the Line
(7). Sort the content of the file
(8). Write one file content to another file
(9). Exit

๐Ÿ‘ค Author

Khansa Bint-e-Zia


๐Ÿ“„ License

This project is licensed under the MIT License โ€” see the LICENSE file for details.


Built with โค๏ธ as a Data Structures & Algorithms project in Java

About

๐Ÿ“ Java-based text file manipulation tool using custom Stack & LinkedList. Features: sort, reverse, duplicate removal, cut, copy, paste, and file merging.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages