I was checking if I could make a program that searches for a certain word on a site. It that word was on it, it would do a system.out.println(); if it wasn't, it would simulate pressing f5 and loop the class.
Here's my code:
N.B: There's two classes, so you can't just copy paste.
My issue lies in the last "if"-statement. It doesn't print inputLine, it always goes to the "else"-statement.
I was trying to make a .containsnot() of some sorts so it could be a "while"-loop, but to no avail...
Any ideas how to fix this?
P.S: I used badfanfiction so my printline wouldn't be massive.
Here's my code:
N.B: There's two classes, so you can't just copy paste.
Code:
[b]//Tabswitch class is so it doesn't loop alt+tab later on[/b]
import java.awt.*;
import java.awt.event.*;
public class Tabswitch {
public static void main(String[] args) throws Exception{
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ALT);
r.keyPress(KeyEvent.VK_TAB);
r.delay(100);
r.keyRelease(KeyEvent.VK_ALT);
r.keyRelease(KeyEvent.VK_TAB);
URLReader a = new URLReader();
}
}
[b]//URLReader class is where my question lies[/b]
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
public class URLReader{
public URLReader() throws Exception{
URL site = new URL("http://kaction.com/badfanfiction/");
BufferedReader in = new BufferedReader(
new InputStreamReader(site.openStream()));
String inputLine;
while((inputLine = in.readLine()) != null)
if(inputLine.contains("the"))
System.out.println(inputLine);
else{
Robot s = new Robot();
s.delay(2000);
s.keyPress(KeyEvent.VK_F5);
s.keyRelease(KeyEvent.VK_F5);
s.delay(2000);
URLReader a = new URLReader();
}
}
}
I was trying to make a .containsnot() of some sorts so it could be a "while"-loop, but to no avail...
Any ideas how to fix this?
P.S: I used badfanfiction so my printline wouldn't be massive.


Comment