mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-16 18:59:21 +00:00
Formatted all files to the same standard
This commit is contained in:
@@ -5,72 +5,74 @@ import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
/**
|
||||
* Every instance of this class represents the Model component
|
||||
* in the Model-View-Presenter architectural pattern.
|
||||
* Every instance of this class represents the Model component in the
|
||||
* Model-View-Presenter architectural pattern.
|
||||
*
|
||||
* It is responsible for reading and loading the contents of a given file.
|
||||
*/
|
||||
public class FileLoader {
|
||||
|
||||
|
||||
/**
|
||||
* Indicates if the file is loaded or not.
|
||||
*/
|
||||
private boolean loaded = false;
|
||||
|
||||
|
||||
/**
|
||||
* The name of the file that we want to load.
|
||||
*/
|
||||
private String fileName;
|
||||
|
||||
|
||||
/**
|
||||
* Loads the data of the file specified.
|
||||
*/
|
||||
public String loadData() {
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new FileReader(new File(this.fileName)));
|
||||
BufferedReader br = new BufferedReader(new FileReader(new File(
|
||||
this.fileName)));
|
||||
String text = "";
|
||||
String line = "";
|
||||
|
||||
while( (line = br.readLine()) != null ) {
|
||||
|
||||
while ((line = br.readLine()) != null) {
|
||||
text += line + "\n";
|
||||
}
|
||||
|
||||
|
||||
this.loaded = true;
|
||||
br.close();
|
||||
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
catch(Exception e) {
|
||||
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the path of the file to be loaded, to the given value.
|
||||
*
|
||||
* @param fileName The path of the file to be loaded.
|
||||
* @param fileName
|
||||
* The path of the file to be loaded.
|
||||
*/
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return fileName The path of the file to be loaded.
|
||||
*/
|
||||
public String getFileName() {
|
||||
return this.fileName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return True, if the file given exists, false otherwise.
|
||||
*/
|
||||
public boolean fileExists() {
|
||||
return new File(this.fileName).exists();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return True, if the file is loaded, false otherwise.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user