Let's don't look at the file cross which is from the Djala doc either package it can be useful for manipulating 2
files on the system that is you can use this class to do things like creating files creating directories 3
deleting files and directories renaming files and so on. 4
We will simply add more. 5
Very we'll see some of the things that we can do with this class. 6
We know that every file or directory on the disk has a certain unique but that is a part is used to 7
locate the file on the directory and an instance of a file class would represent such a spot and it 8
is instantiated as shown here. 9
So telepresence a pop to a file order directory but not the contents of the file. 10
Our first impression looking at this constructor would be that a file instance the presence contents 11
of a file and that is not the case here. 12
The string in the constructor is referred to as up happening not that the constructor does not throw 13
an exception even if the pathname is invalid here Aalto just know that. 14
But file input stream on file output stream classes have constructors which text file instance us an 15
input. 16
But I believe the constructors that we used which took filename as input are more commonly used on here 17
are some really fundamental things which we need to know about the differences at the OS level. 18
First is the directory separator in the pathname on Windows a backslash is used to separate the directories 19
in the back. 20
Name one on Unix forward slashes. 21
There is also something called root directory which would be the first or the top most directly in the 22
directory hierarchy. 23
On Windows it would be drives like C and D. 24
Well on Unix it would be represented by the forward slash on Unix if the bottom is G-I the slash em 25
then the root would be the directory in which geode is present. 26
So Geordi will not be the root but the directory in the G ID is present. 27
That would be the root directory. 28
Now as for the lines operators in a text file windows users garridge feet followed immediately by newline 29
. 30
On Unix it is just the new line coming to pathname. 31
It can be either obsolete. 32
Really do an absolute pathname points to the same location regardless of the current working directory 33
and current What can that accrete which is also referred to as a user directory would be the directory 34
in which you are Jola interpreter is running on my machine. 35
It would be geoduck slash Dymo in the C drive. 36
You can also know that we are the user be our system property which is accessible from the get Propertius 37
method of the system class. 38
Now when it comes to relate to power them it is resolved with us but what wouldn't be accurate. 39
So does it relate to the working directory. 40
If it is not me or it should get clear in the demo and it is actually time for the demo one I'll sort 41
of switch over to our editor. 42
OK in this demo we're going to look at two new methods and here they are in the IRA demo glass. 43
So let's just go ahead and look at the first matter. 44
And here it is. 45
So here we are first creating an instance of file and we are passing a file name which is valid and 46
or jpeg. 47
And here it is and are jpeg within the within that demo project. 48
So it is within the demo folder. 49
But here we also have this. 50
So within the models as sarcy directory. 51
And here we are using two dots. 52
So we could have just had the filename as demos slash growled and Argiope. 53
But I just wanted to show this notation here. 54
Here are two dots indicates that it is referencing the parent directory. 55
OK. 56
Which means the directory in which sources present. 57
OK so that we can do it this way or we can just remove this part on hybridize just valued and Arjay 58
peg written Demel. 59
And here we are using an extra slash. 60
It's actually only one slash but ngalo we know that slash needs to be Skipwith and there's Slash. 61
So to try we have boost lushest here. 62
And so these are all the different methods. 63
There are many methods within the file class. 64
So we are also trying many of these methods. 65
So let's just go ahead and actually run it and then we can look at each of the methods 66
and here it is 67
OK so the get absolute bat is giving us the absolute path off the file. 68
Q So you can see the entire file including Pop name including SIRC under two dots. 69
Now there is something called Get canonical bot. 70
So that's another matter and it would actually read the simple pathname. 71
So it's not going to include sarcy. 72
And the two dots. 73
And here we are trying to create a new file. 74
And all of these methods as you can see are invoked on F which is the end of it is a variable that is 75
referencing file instance. 76
So but these do not get canonical path and create new file have to be inside the try catch block. 77
Uncreate you'll find we're trying to create a new file. 78
But in this case since the file is already there it read and save files. 79
Then the next one is separate or so here it's actually a field. 80
It's not a matter it's a field unseparated gives the the operator that separates the directory so it's 81
a directory separator that will get in here. 82
The operator operates their directories in the path name. 83
So it is a backward slash since it's Windows system on separator. 84
It is also another method which simply gives the same thing it gives the same thing but it returns a 85
car where whereas operator returns this string. 86
Now if you're let's say if you are creating some file on a particular machine and you want to clear 87
this up in some kind of a directory in some directory then you it's better to use when you're creating 88
the file name it's better to use. 89
You'll make use of this separator field. 90
OK. 91
That way it will be specific to that directory to that machine on which the program is running. 92
OK. 93
So I just kind of like form independent. 94
No. 95
So instead of hard coding the separator you can make use of this. 96
So that's not I in get parents integrated into the parent off the firewall and ogic bit under the tree 97
. 98
That would include the entire structure until wild and Argiope EC. 99
OK excluding Reiland or depict in this case it's also retaining SIRC and double dots which would mean 100
only this part the G ID under Obama and the next one is Last-Modified. 101
So it does run the firewall's Last-Modified and it gives the time in milliseconds so milliseconds from 102
1970. 103
So that's qualis the epoch time. 104
And so it would be the number of milliseconds since that particular time. 105
Now if you use that milieu if this if this number if you if you convert it into ears it would be around 106
46 years. 107
You can actually try it in Google just search for milliseconds to ears and give this number and you 108
should get it. 109
Next one as whether the file exists yes whether the file is a file. 110
Yes it's a file on the next one is whether it's a directory. 111
No it's not. 112
So it's false on the next one is the lend method which will read under size of the file which is around 113
5 and B. 114
Next I'm printing though my working directory the user directory. 115
And as we mentioned we are going to in the get property matter with the system property user Aiyar and 116
my directory is this one. 117
Jerry strategem on next. 118
We are trying to create some directories here. 119
So first thing we are doing is we are creating a new file instance passing the new directory name and 120
we are doing it in a relative path. 121
OK. 122
We are not using the absolute path which means that my current directory is a demo Jayati and Emel unbuttoned 123
them all I want to create this directory. 124
So undergirds set rules. 125
So let me just refresh your head fly on them all. 126
And as you can see that as directory has been created so are done so true here. 127
So the method for that is and. 128
BAIER make that accrete. 129
And next we are creating one more directory within that directory. 130
So if you go here you can also see that there is the best directory that God created. 131
Next we are trying to delete that as a directory. 132
And here it says false. 133
It cannot do it because there is some content within the desk directory. 134
If it is empty which means that there is no file or not directory only that it will succeed. 135
It really is not true. 136
Now in the next line we are trying to create multiple directories within test directory. 137
So we are trying to create a directory called test run unbid within test run we are trying to create 138
another directory called Test 2 and we are using the same method maybe undertreatment pretence of. 139
So we cannot do that. 140
Unflawed that we need to use this as the plural form off make a bit Acree and that would allow us to 141
create that directories. 142
But just one. 143
Understood. 144
So you need to use and keep the eye on this for that. 145
So that's the thing. 146
And next Finally here in this matter we are creating a new instance called Temp dot DXi and we are creating 147
the new file. 148
I notice that the file got signed should have been created. 149
Maybe the child was already there. 150
Yeah I think in my test runs the file was there so it got created and after that the next step is to 151
rename that file name to a different name and in order to get the argument that this method is a new 152
file Newfies instance with the new name. 153
But in this sense it's just not the name. 154
But we are also including a directory name here as did a tree. 155
So what is going to happen is this is the name of the new file. 156
And since the directory name is there this file time file temp.txt is actually moved into this directory 157
. 158
OK with this name. 159
So if you go here and test directory you can see this file 1.60. 160
So that's how you load more files. 161
You can move files and you can also rename them and now let's look at the second matter which is Karlos 162
did reflector. 163
Now sometimes we want to look at the contents of a particular directory what files and directories that 164
a particular directory has on the immediate files not a directory on the Internet within that directory 165
. 166
But our immediate three appearing directories on files appearing in a directory. 167
Now if you want to do that if you want to see what what directories on file are appearing in a particular 168
directory then you would use. 169
And then we can use this method for that there is a method called us list. 170
So here we are creating a file instance and it is referencing the current directory and the current 171
directory would be the current working directory which is there. 172
And within that directory We want to list all the directories and the files that are appearing immediately 173
within that. 174
And for that we use the list muttered Birgitta dense string theory which includes that it would include 175
all the names of the directories on those files. 176
So I'm passing this but I'm going to require a placeholder which is initially set to false. 177
So if it is false it means that we want to list all of them here. 178
Gayford is false. 179
We are going to just invoke this method. 180
So here you can see that there are all these different files and these are all files are in some directories 181
here underground and Argiope quite also is here. 182
Now if I wanted just if I passed through we are going into the last block on the block we are invoking 183
a different version of the list method which takes a filtering criteria. 184
Now sometimes we want to just look for files having certain extension for example. 185
So in our case we want to just look for the epic files within the demo project and we want to ignore 186
all the other directories on any other files like that the extreme. 187
We just want to look for only the big files. 188
So there is a certain filtering criteria. 189
So the method argument here is an interface it's called as a filename filter it's an interface and using 190
that interface if you can implement that interface and you can specify your criteria. 191
And here it is at the bottom after that name. 192
After this class I would add this new class called it a pre-filter be a filter I need implements to 193
find them filter which has this method called accept. 194
So in the Axert I have the filtering criteria. 195
I'm saying that if the current file that is passed here it and spitted git big dodgy .jpg are the caps 196
aren't gaps Dundon are true. 197
Otherwise you would read enough files. 198
Ok so. 199
So let me pass this class. 200
The instance of ductless to the list knotter the list method vote in lieu of the accept method with 201
each file within the current current directory each file and the directory name. 202
OK so it would pass. 203
Each of them to the X up method in this that has been defined in this class. 204
Now if I had to run this as you can see it is just printing only dog OPG and Dot end caps and ignoring 205
everything else in that directory. 206
So that's how you would look for 500 or Chris. 207
In any given electorate immediately appearing files on directories. 208
So that's about it. 209
That's how you would manipulate files on the system. 210
OK you can use them for creating directories deleting directories or renaming files. 211
Looking at the fire sun looking at the file properties and so on. 212
So go ahead and you can find the updated class and the resources section and you can play around with 213
it and look at other kinds of matters that are there in the final class and that's about it. 214
Thank you and happy coding