mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
Renamed method for clarity.
This commit is contained in:
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -8520,7 +8520,7 @@ src/forge/EndOfCombat.java -text svneol=native#text/plain
|
||||
src/forge/EndOfTurn.java svneol=native#text/plain
|
||||
src/forge/ExternalPanel.java svneol=native#text/plain
|
||||
src/forge/FileFinder.java -text svneol=native#text/plain
|
||||
src/forge/FileUtil.java -text svneol=native#text/plain
|
||||
src/forge/FileUtil.java svneol=native#text/plain
|
||||
src/forge/GUI_DeckAnalysis.java -text svneol=native#text/plain
|
||||
src/forge/GUI_Filter.java -text svneol=native#text/plain
|
||||
src/forge/GUI_ImportPicture.java -text svneol=native#text/plain
|
||||
|
||||
@@ -1,71 +1,68 @@
|
||||
package forge;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import forge.error.ErrorViewer;
|
||||
|
||||
|
||||
public class FileUtil {
|
||||
public static boolean doesFileExist(String filename) {
|
||||
File f = new File(filename);
|
||||
return f.exists();
|
||||
}
|
||||
|
||||
public static void writeFile(String filename, List<String> data) {
|
||||
writeFile(new File(filename), data);
|
||||
}
|
||||
|
||||
//writes each element of ArrayList on a separate line
|
||||
//this is used to write a file of Strings
|
||||
//this will create a new file if needed
|
||||
//if filename already exists, it is deleted
|
||||
public static void writeFile(File file, List<String> data) {
|
||||
try {
|
||||
Collections.sort(data);
|
||||
|
||||
BufferedWriter io = new BufferedWriter(new FileWriter(file));
|
||||
for(int i = 0; i < data.size(); i++)
|
||||
io.write(data.get(i) + "\r\n");
|
||||
|
||||
io.flush();
|
||||
io.close();
|
||||
} catch(Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("FileUtil : writeFile() error, problem writing file - " + file + " : " + ex);
|
||||
}
|
||||
}//writeFile()
|
||||
|
||||
public static ArrayList<String> readFile(String filename) {
|
||||
return readFile(new File(filename));
|
||||
}
|
||||
|
||||
//reads line by line and adds each line to the ArrayList
|
||||
//this will return blank lines as well
|
||||
//if filename not found, returns an empty ArrayList
|
||||
public static ArrayList<String> readFile(File file) {
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
BufferedReader in;
|
||||
|
||||
try {
|
||||
if(file == null || !file.exists()) return list;
|
||||
|
||||
|
||||
in = new BufferedReader(new FileReader(file));
|
||||
|
||||
String line;
|
||||
while((line = in.readLine()) != null)
|
||||
list.add(line);
|
||||
} catch(Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("FileUtil : readFile() error, " + ex);
|
||||
}
|
||||
|
||||
return list;
|
||||
}//readFile()
|
||||
package forge;
|
||||
|
||||
import forge.error.ErrorViewer;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class FileUtil {
|
||||
public static boolean doesFileExist(String filename) {
|
||||
File f = new File(filename);
|
||||
return f.exists();
|
||||
}
|
||||
|
||||
public static void writeFile(String filename, List<String> data) {
|
||||
writeFile(new File(filename), data);
|
||||
}
|
||||
|
||||
//writes each element of ArrayList on a separate line
|
||||
//this is used to write a file of Strings
|
||||
//this will create a new file if needed
|
||||
//if filename already exists, it is deleted
|
||||
public static void writeFile(File file, List<String> data) {
|
||||
try {
|
||||
Collections.sort(data);
|
||||
|
||||
BufferedWriter io = new BufferedWriter(new FileWriter(file));
|
||||
for(int i = 0; i < data.size(); i++)
|
||||
io.write(data.get(i) + "\r\n");
|
||||
|
||||
io.flush();
|
||||
io.close();
|
||||
} catch(Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("FileUtil : writeFile() error, problem writing file - " + file + " : " + ex);
|
||||
}
|
||||
}//writeAllDecks()
|
||||
|
||||
public static ArrayList<String> readFile(String filename) {
|
||||
return readFile(new File(filename));
|
||||
}
|
||||
|
||||
//reads line by line and adds each line to the ArrayList
|
||||
//this will return blank lines as well
|
||||
//if filename not found, returns an empty ArrayList
|
||||
public static ArrayList<String> readFile(File file) {
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
BufferedReader in;
|
||||
|
||||
try {
|
||||
if(file == null || !file.exists()) return list;
|
||||
|
||||
|
||||
in = new BufferedReader(new FileReader(file));
|
||||
|
||||
String line;
|
||||
while((line = in.readLine()) != null)
|
||||
list.add(line);
|
||||
} catch(Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("FileUtil : readFile() error, " + ex);
|
||||
}
|
||||
|
||||
return list;
|
||||
}//readFile()
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public class DeckManager {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
writeFile();
|
||||
writeAllDecks();
|
||||
}
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ public class DeckManager {
|
||||
return deckName.replaceAll("[^-_$#@.{[()]} a-zA-Z0-9]", "");
|
||||
}
|
||||
|
||||
public void writeFile() {
|
||||
public void writeAllDecks() {
|
||||
try {
|
||||
//store the files that do exist
|
||||
List<File> files = new ArrayList<File>();
|
||||
|
||||
Reference in New Issue
Block a user