0% found this document useful (0 votes)
57 views13 pages

File Application Mad

This document summarizes a mini project that involves creating an Android application to edit and save files. The application contains a text field, and buttons to create, save, and open files. It allows the user to write text, save it as a file when the create button is pressed, and update the saved file by pressing save. The open button displays the contents of the previously saved file. The code implementation involves writing and reading files from the device storage using Kotlin functions.

Uploaded by

VINAY H N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views13 pages

File Application Mad

This document summarizes a mini project that involves creating an Android application to edit and save files. The application contains a text field, and buttons to create, save, and open files. It allows the user to write text, save it as a file when the create button is pressed, and update the saved file by pressing save. The open button displays the contents of the previously saved file. The code implementation involves writing and reading files from the device storage using Kotlin functions.

Uploaded by

VINAY H N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

MINI PROJECT PRESENTATION

FILE APPLICATION

Team members

Simran K (4GM19IS050)
Tejas H (4GM19IS058)
Vasundhara AM (4GM19IS060)
Vinay HN (4GM19IS061)
Contents:
• Abstract
• Introduction
• Problem statement
• Design
• Software and hardware requirements
• Implementation
• Snapshots
Abstract:
• The project titled “ FILE SAVING APPLICATION” is an Android application
which is developed to edit and save the files.

• This project contains one text filed, three buttons namely -Create button where the
text should be saved as a text file in MkSD card. Save button-should be pressed to
store the latest content to the file, Open button-it should display the contents from
the previously stored files in the Text box and toast to display alert message.
Introduction:

• What is file?
• A file is a common storage unit in a computer.
• All programs and data are “Written” into a file and “read” from a file.
• The file system used by Android is comparable to other platforms' disk-based
file systems. This project shows how to perform basic file-related tasks in
your app.
• A File object is used for reading or writing large amount of data in a linear
fashion.
Problem Statement:
• Write a program to create an activity having a Text box, and also Save, Open
and Create buttons. The user has to write some text in the Text box. On
pressing the Create button the text should be saved as a text file in MkSD card.
On subsequent changes to the text, the Save button should be pressed to store
the latest content to the same file. On pressing the Open button, it should
display the contents from the previously stored files in the Text box. If the user
tries to save the contents in the Textbox to a file without creating it, then a toast
message has to be displayed saying “First create a file “.
Design:
• Hardware requirements:
4GB RAM
2GB Hard-Disk
I3 processor

• Software requirements:
kotlin/java
android SDK
android studio
SDK tools
Code:
package `in`.edu.cambridge.fileapplication
import android.content.Context //used to do application level operations-launching acts
import android.os.Bundle //pass the data between activities
import android.util.Log //is used for testing non android host
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity //to import new platform features
import java.io.*

class MainActivity : AppCompatActivity() {

private lateinit var text_input: EditText //lateinit- allows initializing a null property
private lateinit var saveBtn : Button
private lateinit var openBtn : Button
private lateinit var open_text : TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

text_input = findViewById(R.id.text_input)
open_text = findViewById(R.id.open_file_text)

openBtn = findViewById(R.id.open_file)
saveBtn = findViewById(R.id.save_file)

saveBtn.setOnClickListener {
var data : String = text_input.text.toString()
writeToFile(data, this)
Toast.makeText(this, "File Saved !", Toast.LENGTH_SHORT).show()
}

openBtn.setOnClickListener {
var data = readFromFile(this)
open_text.text = data
}
}
private fun writeToFile(data: String, context: Context) {
try {
val outputStreamWriter =
OutputStreamWriter(context.openFileOutput("file.txt",Context.MODE_PRIVATE))
outputStreamWriter.write(data)
outputStreamWriter.close()
} catch (e: IOException) {
Log.e("Exception", "File write failed: " + e.toString())
}
}
private fun readFromFile(context: Context): String? {
var str = ""
try {
val inputStream: InputStream = context.openFileInput("file.txt") //it reads the data from file in terms
of bytes
if (inputStream != null) { //it checks whether inputstream has any data
val inputStreamReader = InputStreamReader(inputStream) // it reads bytes & decode into characters
val bufferedReader = BufferedReader(inputStreamReader) //reads a couple of characters from IS
var receiveString: String? = ""
val stringBuilder = StringBuilder() //used to create mutable string
while (bufferedReader.readLine().also { receiveString = it } != null) {
stringBuilder.append("\n").append(receiveString)
}
inputStream.close()
str = stringBuilder.toString()
}
} catch (e: FileNotFoundException) {
Log.e("Main Activity", "File not found: " + e.toString())
} catch (e: IOException) {
Log.e("Main Activity", "Can not read file: $e")
}
return str
}
}
Snapshots-output

You might also like