Skip to content

Instantly share code, notes, and snippets.

@owniz
Forked from GrenderG/GCIOTemplate.java
Created April 5, 2016 15:46
Show Gist options
  • Save owniz/24e732c82d22f4325c0b29ab361881d2 to your computer and use it in GitHub Desktop.
Save owniz/24e732c82d22f4325c0b29ab361881d2 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.ArrayList;
public class GCIOTemplate {
public static List<String> readFile(String path, String fileName) throws IOException {
Path inFilePath = Paths.get(path, fileName);
Charset charset = Charset.forName("ISO-8859-1");
return Files.readAllLines(inFilePath, charset);
}
public static void writeFile(String filePath, ArrayList<String> inputToWrite) throws IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter(filePath));
for (int i = 0; i < inputToWrite.size(); i++) {
bw.write("Case #" + (i + 1) + ": " + inputToWrite.get(i));
if (i < inputToWrite.size() - 1)
bw.newLine();
}
bw.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment