File
(and directories)
All the variables live in memory and disappear when computer in turn off.
To make them persistent
, they have to be saved into file (and conversely read from file).
In Java, all the elements from a files' structure are represented by an instance of
File
as illustrated below:
try {
File file = new File("/home/thiry/eclipse-workspace/Course/catalog.csv");
if (! file.exists())
file.createNewFile();
File parent = new File(file.getParent());
String[] files = parent.list();
File file0;
for(String filename : files) {
file0 = new File(filename);
if(! file0.isDirectory()) System.out.println(file0);
}
} catch (Exception e) {
e.printStackTrace();
}
Exercise:
- What operation is realized by the preceding program ?
- Can you represent the class File in UML to well show the operations proposed ?
- From the documentation, what are other interesting operations ?
6 - 12
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented