Word List Creator 06-22-2013, 03:54 PM
#1
I tried making a simple word list generator in java today and came up with this thing. It reads a URL and writes unique words to a file in separate lines if its length is more than or equal to 4.
WLC.java
ReadURL.java
Screen Shot :
![[Image: love_7.jpg]](http://s3.postimg.org/jilpq00wj/love_7.jpg)
![[Image: love_8.jpg]](http://s1.postimg.org/fgrl1l833/love_8.jpg)
Cheers
WLC.java
Code:
/* Made by Solixious Klein */
import javax.swing.*;
import java.awt.event.*;
import java.io.File;
public class WLC extends JFrame implements ActionListener
{
private static final long serialVersionUID = 1L;
private JLabel urlLabel,outputFileLabel;
private JTextField urlField,fileField;
private JButton browseButton,generateButton,closeButton;
private JFileChooser saveFileDialog;
public WLC()
{
setLayout(null);
setTitle("Word List Creator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
urlLabel=new JLabel("URL to Scan");
outputFileLabel=new JLabel("Output File");
urlField=new JTextField();
fileField=new JTextField();
browseButton=new JButton("Browse");
generateButton=new JButton("Start");
closeButton=new JButton("Close");
browseButton.addActionListener(this);
generateButton.addActionListener(this);
closeButton.addActionListener(this);
urlLabel.setBounds(30,30,100,20);
outputFileLabel.setBounds(30, 60, 100, 20);
urlField.setBounds(150, 30, 200, 20);
fileField.setBounds(150, 60, 200, 20);
browseButton.setBounds(370,60,80,20);
generateButton.setBounds(150,100,80,20);
closeButton.setBounds(250,100,80,20);
add(urlLabel);
add(outputFileLabel);
add(urlField);
add(fileField);
add(browseButton);
add(generateButton);
add(closeButton);
setBounds(200,200,500,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object event=e.getSource();
if(event==browseButton)
{
saveFileDialog=new JFileChooser();
saveFileDialog.setAcceptAllFileFilterUsed(false);
saveFileDialog.setFileFilter(new TextFilter());
int ret=saveFileDialog.showDialog(this,"Save To Text File");
if(ret==JFileChooser.APPROVE_OPTION)
{
String path=saveFileDialog.getSelectedFile().getPath();
path=path.toLowerCase();
if(path.endsWith("txt"))
fileField.setText(path);
else
fileField.setText(path+".txt");
}
}
else if(event==generateButton)
{
ReadURL r=new ReadURL();
String urlString=urlField.getText();
String fileName=fileField.getText();
if(!urlString.startsWith("http://"))
urlString="http://"+urlString;
try
{
r.read(urlString, fileName);
}
catch(Exception e1)
{
e1.printStackTrace();
}
}
else if(event==closeButton)
{
dispose();
System.exit(0);
}
}
public static void main(String[] args)
{
new WLC();
}
class TextFilter extends javax.swing.filechooser.FileFilter
{
public boolean accept(File f)
{
if (f.isDirectory())
return true;
String s = f.getName();
s=s.toLowerCase();
if (s.endsWith(".txt"))
return true;
return false;
}
public String getDescription()
{
return "Text Files(*.txt)";
}
}
}ReadURL.java
Code:
import java.net.*;
import java.io.*;
public class ReadURL
{
public void read(String urlString,String fileName) throws Exception
{
URL url = new URL(urlString);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String inputLine;
File f=new File(fileName);
if(!f.exists())
f.createNewFile();
BufferedWriter bw=new BufferedWriter(new FileWriter(f,true));
while ((inputLine = in.readLine()) != null)
{
inputLine=strip(inputLine);
String st[]=inputLine.split(" ");
for(int i=0;i<st.length;i++)
{
if(st[i].length()>=4) //length should be more than 3
{
int flag=0;
for(int j=0;j<i;j++)
{
if(st[j].equals(st[i]))
{
flag=1;
break;
}
}
if(flag==0)
{
bw.write(st[i]);
bw.newLine();
}
}
}
}
in.close();
bw.close();
optimize(fileName); //sort the words in file and also remove the duplicate words
}
public void optimize(String fileName)throws Exception
{
BufferedReader br=new BufferedReader(new FileReader(fileName));
int ctr=0;
while(br.readLine()!=null)
ctr++;
br.close();
br=new BufferedReader(new FileReader(fileName));
String words[]=new String[ctr];
for(int i=0;i<ctr;i++)
{
words[i]=br.readLine();
}
//sorting
for(int i=0;i<ctr;i++)
{
int min=i;
for(int j=i+1;j<ctr-1;j++)
{
if(words[min].compareTo(words[j])<0)
min=j;
}
if(min!=i)
{
String temp=words[min];
words[min]=words[i];
words[i]=temp;
}
}
br.close();
BufferedWriter bw=new BufferedWriter(new FileWriter(fileName,false));
for(int i=0;i<ctr;i++)
{
if(i>0)
if(words[i].equals(words[i-1]))
continue;
bw.write(words[i]);
bw.newLine();
}
bw.close();
}
public String strip(String str)
{
String st="";
for(int i=0;i<str.length();i++)
{
char c=str.charAt(i);
if((c>='a' && c<='z') || (c>='A' && c<='Z'))//consider alphabets only
st=st+String.valueOf(c);
else if(!st.endsWith(" "))//separate various words with a single blank space
{
st=st+" ";
}
}
return st;
}
}Screen Shot :
Spoiler:
![[Image: love_7.jpg]](http://s3.postimg.org/jilpq00wj/love_7.jpg)
![[Image: love_8.jpg]](http://s1.postimg.org/fgrl1l833/love_8.jpg)
Cheers
Folow me on My YouTube Channel if you're into art.

![[+]](https://sinister.li/images/modern/collapse_collapsed.png)
![[Image: OilyCostlyEwe.gif]](http://fat.gfycat.com/OilyCostlyEwe.gif)

![[Image: 2YpkRjy.png]](http://i.imgur.com/2YpkRjy.png)
miling: