Originally posted by crazystone82
Can you run this one and then post the line that is reported to have the exception
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
public class remotefileupload implements ActionListener {
JTextField sourcefield,destinationfield;
JLabel sourceLabel,destinationLabel;
JButton submit;
FileInputStream fin;
FileOutputStream fout;
URL destinationurl;
URLConnection connection;
OutputStreamWriter out;
BufferedReader in;
remotefileupload() {
//WindowUtilities.setNativeLookAndFeel();
JFrame f = new JFrame("This is a test");
f.setSize(300,300);
Container content = f.getContentPane();
content.setBackground(Color.white);
content.setLayout(null);
sourceLabel=new JLabel("Source Path");
sourceLabel.setBounds(10,20,70,20);
sourcefield=new JTextField(30);
sourcefield.setBounds(90,20,90,20);
destinationLabel=new JLabel("Destination");
destinationLabel.setBounds(10,50,70,20);
destinationfield=new JTextField(30);
destinationfield.setBounds(90,50,90,20);
submit=new JButton("Submit");
submit.setBounds(40,80,90,30);
content.add(sourceLabel);
content.add(sourcefield);
content.add(destinationLabel);
content.add(destinationfield);
content.add(submit);
submit.addActionListener(this);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}});
f.setVisible(true);
//f.addWindowListener(new ExitListener());
}
public void actionPerformed(ActionEvent ae) {
int i;
String str=ae.getActionCommand();
if(str.equals("Submit")) {
try {
fin = new FileInputStream(sourcefield.getText());
in = new BufferedReader(new InputStreamReader(fin));
//fout =new FileOutputStream(destinationfield.getText());
String destination=destinationfield.getText();
destinationurl = new URL(destination);
connection = destinationurl.openConnection();
connection.setDoOutput(true);
//connection.connect();
out = new OutputStreamWriter(connection.getOutputStream());
do {
i = fin.read();
if(i != -1)
out.write(i);
}while(i != -1);
JOptionPane.showConfirmDialog(null,"success", "success", JOptionPane.YES_NO_OPTION);
fin.close();
out.close();
in.close();
}
catch(FileNotFoundException e) {
System.out.println("Input File not found");
return;
}
catch (MalformedURLException e) {
e.printStackTrace(); // new URL() failed
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(" Copy file frm to");
return;
}
catch(IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args)
{
new remotefileupload();
}
}
Comment