days on this project.
how to to show number of words, lines in file?
program need to copy file to another file and add 9 words on each line?
how to add a delimiter to the program to look for a word is a string
ends with blank space, a comma, a period?
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
public class FileChooserGUI extends JFrame
{
public static final JFileChooser chooser = null;
JButton button1;
JPanel panel;
static JLabel R1;
static JLabel R2;
static JLabel R3;
//input = inFile.readLine(); //read a line
static int wordCount = 0;
public static Scanner input;
FileChooserGUI()
{ //Constructor
panel = new JPanel(new GridLayout(9,10)); //first one increase height
//second one increase width
panel.setSize(300,200);
R1 = new JLabel("Number of Words: "); //1st label
R2 = new JLabel("Number of Lines: "); //2nd label
R3 = new JLabel("Target Words: "); //3rd label
button1 = new JButton("START");
panel.add(R1); //adding three labels to the window frame
panel.add(R2); //adding button 2
panel.add(R3); //adding button 3
panel.add(button1); //adding 1 button to window frame
add(panel); //adding panel to window
R1.setVisible(false);
R2.setVisible(false);
R3.setVisible(false);
setVisible(true);
pack();
//button1.addActionListener(new ActionListener());
}
public void actionPerformed(ActionEvent e)
{
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
}
public static class transferFiles
{
private static final String selectedFile = null;
public static void main(String args[])throws Exception{
try{
int code = chooser.showOpenDialog(null);
if (code == JFileChooser.APPROVE_OPTION)
{
File selectedFile = chooser.getSelectedFile();
Scanner input = new Scanner(selectedFile);
}
while (input.hasNext())
{ //while loop to count all thw words in txt file
++wordCount;
input.next();
}
}
catch (Exception output)
{ //catch an error on getting name of file
output.printStackTrace();
}
String out = selectedFile.getName(); //getname of file
R1.setText("File Name is : " + out);
R2.setText("File Size is : " +Long.toString(size));
R3.setText("Number of words counted : " +Integer.toString(wordCount));
R1.setVisible(true);
R2.setVisible(true);
R3.setVisible(true);
File output = chooser.getSelectedFile();
i= new FileReader(selectedFile);
FileWriter o = new FileWriter(output);
while(((i).hasNext())
{
o.write(i);
}
}
}
}

New Topic/Question
This topic is locked



MultiQuote






|