LuckyOwl LuckyOwl - 2 years ago 61
Java Question

The file is not being printed out,what am I doing wrong?

I have been trying to get the output of this code to be printed on a .txt file, however I getting an empty file as an output, but I see the correct results in the console, so the problem is with the StreamWriter I think.

So what am I doing wrong?

package Hierarchies;

public static void generateHierarchy() {

Set<Entry<Long, Node>> iterator = graph.entrySet();
int i =0;
for(Entry<Long,Node> e : iterator) {
System.out.println(i++ +" - " +e.getValue().firstParents());


@SuppressWarnings({ "resource" })
public static void main(String[] args) throws JWNLException {
// TODO Auto-generated method stub
dictionary = Dictionary.getDefaultResourceInstance();

File dir = new File("C:/Users/D060891/Desktop/Thesis/sentencesNYT");

for (File file : dir.listFiles()) {

try {
BufferedReader input = new BufferedReader(new FileReader(file));
String line;

while ((line = input.readLine()) != null) {
catch (IOException e) {

PrintStream out;
try {
out = new PrintStream(new FileOutputStream("output.txt"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block

Answer Source

I do not see you writting anything to the file. I just see how you create a PrintStream to a file and assign it to System.out, but then you do not print nothing. Call generateHierarchy() after you asign out

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download