Skip to content

Instantly share code, notes, and snippets.

@andrewmd5
Last active August 29, 2015 13:57
Show Gist options
  • Save andrewmd5/9656382 to your computer and use it in GitHub Desktop.
Save andrewmd5/9656382 to your computer and use it in GitHub Desktop.
Cleans out a paypal cvs document to only leave what you received
public class CVSFormat {
public static void main(String[]args)throws IOException {
// construct temporary file
File inputFile = new File("statements.csv");
File tempFile = new File(inputFile + "temp.csv");
BufferedReader bufferReader = new BufferedReader (new FileReader("statements.csv"));
PrintWriter printWriter = new PrintWriter(new FileWriter (tempFile));
String line = null;
//read from original, write to temporary and trim space, while title not found
while((line = bufferReader.readLine()) !=null) {
if(line.toLowerCase().contains("received")){
System.out.println(line);
printWriter.println(line);
printWriter.flush();
} else{
continue;
}
}
// close readers and writers
bufferReader.close();
printWriter.close();
// delete book file before renaming temp
inputFile.delete();
// rename temp file back to statements.cvs
if(tempFile.renameTo(inputFile)){
System.out.println("Update succesful");
}else{
System.out.println("Update failed");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment