File_Write(Create)_Dart
import "dart:io";
///NOTE :
//File handling is an important part of any programming language
//While programming, you might run into some sort of situation,
// where you need to work on a file stored at a specific location,
// maybe write something on it, read it or anything else. Dart supports
// working with files as well.
// In order to start working, first of all we need to import dart’s inbuilt
// io (input output) library.
// import 'dart:io';
// This library gives us access to a large number of classes, methods
// and properties which we can use to perform various operations. In
// current situation, we need to work with files, hence, we need to
// create an instance of the File class
void main()
{
/// WRITE FILE IN DART
///CREATING ONE (DOC) FILE
File fileObject = new File("myFile.doc");
fileObject.writeAsString("Hello, I am Student of PraxWare Technology");
print("File Created!");
///CREATING SECOND (TXT) FILE
File fileObject1 = new File("myFile.txt");
fileObject1.writeAsString("Hello, we creating a File and Studying File Topic along with create "
" file, read file and delete File");
print("New File Created!");
/// CREATING THIRD (CSV) FILE
File fileObject2 = new File("myFile.csv");
fileObject2.writeAsString("Hello, this is myFile.csv File");
print("csv File Created!");
/// CREATING FOURTH (TXT) FILE
File fileObject3 = new File("practiceRepeat.txt");
fileObject3.writeAsStringSync("File handling is an important part of any programming language.\n"
" In this section,you will learn how to read the file in a dart programming language.\n"
"While programming, you might run into some sort of situation,\n"
"where you need to work on a file stored at a specific location,\n"
"maybe write something on it, read it or anything else. Dart supports\n"
"working with files as well.In order to start working, first of all we need to import dart’s inbuilt\n"
"io (input output) library. import 'dart:io'; This library gives us access to a large number of\n"
" classes, methods and properties which we can use to perform various operations.\n"
" In current situation, we need to work with files, hence, we need to create an instance\n"
"of the File class.");
print("practiceRepeat.txt File Created!");
///CREATING FIFTH (PDF) FILE
File fileObject4 = new File("another.pdf");
fileObject4.writeAsStringSync("While programming, you might run into some sort of situation,"
"where you need to work on a file stored at a specific location,"
"maybe write something on it, read it or anything else. Dart supports"
"working with files as well");
print("another.pdf File Created...");
///CREATING SIXTH (EXCEL) FILE
File fileObject5 = new File("practicExcel.xlsx");
fileObject5.writeAsStringSync("Hello this is Excel File");
print("This is Excel File...");
///CREATING SEVENTH (TXT) FILE
File fileObject6 = new File("myFile1.txt");
fileObject6.writeAsStringSync("The File class contains methods for manipulating files and"
" their contents. Using methods in this class, you can open and close files, read to and"
" write from them, create and delete them, and check for their existence");
print("myFile1.txt File is Created!");
///CREATING EIGHTH (PDF) FILE
File fileObject7 = new File("myFile2.pdf");
fileObject7.writeAsStringSync("If path is a symbolic link, rather than a file, then the methods"
" of File operate on the ultimate target of the link, except for delete and deleteSync,"
" which operate on the link.");
print("myFile2.pdf File is Created!");
///CREATING NINTH (DOC) FILE
File fileObject8 = new File("myFile3.doc");
fileObject8.writeAsStringSync("A more flexible and useful way to read a file is with a Stream."
" Open the file with openRead, which returns a stream that provides the data in the file"
" as chunks of bytes. Read the stream to process the file contents when available."
" You can use various transformers in succession to manipulate the file content"
" into the required format, or to prepare it for output."
"You might want to use a stream to read large files, to manipulate the data with transformers, or"
" for compatibility with another API, such as WebSockets.");
print("myFile3.doc File is Created!");
///CREATING TENTH (PDF) FILE
File fileObject9 = new File("myFile4.pdf");
fileObject9.writeAsStringSync("A reference to a file on the file system."
"A File holds a path on which operations can be performed. You can get the parent directory "
"of the file using parent, a property inherited from FileSystemEntity."
"Create a new File object with a pathname to access the specified file on the file system"
" from your program.");
print("myFile4.pdf File is Created!");
///CREATING ELEVENTH (CSV) FILE
File fileObject10 = new File("myFile5.csv");
fileObject10.writeAsStringSync("The use of asynchronous methods"
"To avoid unintentional blocking of the program, several methods are asynchronous and return a Future."
" For example, the length method, which gets the length of a file, returns a Future."
" Wait for the future to get the result when it's ready.");
print("myFile5.csv File is Created!");
///CREATING TWELFTH (CSV) FILE
File fileObject11 = new File("myFile6.csv");
fileObject11.writeAsStringSync("This example displays a counter. When the counter changes,"
" write data on disk so you can read it again when the app loads. Where should you store this data?"
"The path_provider package provides a platform-agnostic way to access commonly used locations"
" on the device’s file system. The plugin currently supports access to two file system locations:"
"Temporary directory A temporary directory (cache) that the system can clear at any time."
" On iOS, this corresponds to the NSCachesDirectory. On Android, this is the value that"
" getCacheDir() returns. Documents directory A directory for the app to store files that"
" only it can access. The system clears the directory only when the app is deleted."
" On iOS, this corresponds to the NSDocumentDirectory. On Android, this is the AppData directory.");
print("myFile6.csv File is Created!");
print("\n");
///CREATING THIRTEEN (DOC) FILE
File fileObject12 = new File("myFile7.doc");
fileObject12.writeAsStringSync("");
print("myFile7.doc File is Created!");
}
Comments
Post a Comment