Home » Java » Delimitter and Twitter4J (Java)

Delimitter and Twitter4J (Java)

Posted by: admin June 14, 2018 Leave a comment


I have some code that works with Twitter4J that appends to a text file. After collecting hundreds upon hundreds of tweets, the text document is unfortunately formatted so that each tweet is on the same line. I’ve tried basic empty println() statements before and after the tweet is printed, but this hasn’t helped. But i’ve heard a delimitter or something similar can do the trick? To summarise, i’m looking for a way of ensuring that there is a line of whitespace before and after each tweet is stored in a text document.


// Creates a new File object
fileName = new File("Tottenham.txt");
/* Creates a new FileWriter object - true dictates that the  
   file is appended to, rather than overwritten */
w = new FileWriter(fileName, true);
// Traverses through the list 
for (int i = 0; i < statuses.size(); i++) {
    /* Creates a new status object that holds a single tweet
       stored in the list*/
    Status status = (Status)statuses.get(i);
    /* Declares a new string variable that stores the users
       twitter handle and the content of the tweet */
    String s = status.getUser().getName() + " : " + status.getText();
    // Prints out the string
    // Writes to the File object
// Closes FileWriter after the loop traversal is completed