Hi all,
please send me a source code to transfer a file to a server
running on another pc in the LAN...using JAVA .By getting the source path and destination path through textfield implemented in java swings
Dec 11 '06
24 7411
sorry for double post
the line 137 is
in.close();
sorry for double post
the line 137 is
in.close();
What happens if you run it like this? -
-
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 {
-
try {
-
fin = new FileInputStream(sourcefield.getText());
-
}
-
catch(FileNotFoundException e) {
-
System.out.println("Input File not found");
-
return;
-
}
-
try {
-
//fout =new FileOutputStream(destinationfield.getText());
-
String destination=destinationfield.getText();
-
destinationurl = new URL(destination);
-
connection = destinationurl.openConnection();
-
connection.setDoOutput(true);
-
//connection.connect();
-
}
-
catch (MalformedURLException e) {
-
e.printStackTrace(); // new URL() failed
-
}
-
catch (IOException e) {
-
System.out.println("unable to open");// openConnection() failed
-
}
-
/*catch(FileNotFoundException e)
-
-
{
-
System.out.println("Output File not found");
-
return;
-
}*/
-
}
-
catch(ArrayIndexOutOfBoundsException e) {
-
System.out.println(" Copy file frm to");
-
return;
-
}
-
try {
-
out = new OutputStreamWriter(connection.getOutputStream());
-
in = new BufferedReader(new InputStreamReader(fin));
-
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(IOException e) {
-
e.printStackTrace();
-
}
-
}
-
}
-
-
-
public static void main(String[] args)
-
{
-
new remotefileupload();
-
-
-
}
-
}
-
-
if i run the program i displays two label boxes as well as textbox that we given in the program.when click the submit button it fires the alert box for confirmation but it also throws the runtime exceptions that i posted in last reply -
-
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 {
-
try {
-
fin = new FileInputStream(sourcefield.getText());
-
}
-
catch(FileNotFoundException e) {
-
System.out.println("Input File not found");
-
return;
-
}
-
try {
-
//fout =new FileOutputStream(destinationfield.getText());
-
String destination=destinationfield.getText();
-
destinationurl = new URL(destination);
-
connection = destinationurl.openConnection();
-
connection.setDoOutput(true);
-
//connection.connect();
-
}
-
catch (MalformedURLException e) {
-
e.printStackTrace(); // new URL() failed
-
}
-
catch (IOException e) {
-
System.out.println("unable to open");// openConnection() failed
-
}
-
/*catch(FileNotFoundException e)
-
-
{
-
System.out.println("Output File not found");
-
return;
-
}*/
-
}
-
catch(ArrayIndexOutOfBoundsException e) {
-
System.out.println(" Copy file frm to");
-
return;
-
}
-
try {
-
out = new OutputStreamWriter(connection.getOutputStream());
-
in = new BufferedReader(new InputStreamReader(fin));
-
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(IOException e) {
-
e.printStackTrace();
-
}
-
}
-
}
-
-
-
public static void main(String[] args)
-
{
-
new remotefileupload();
-
-
-
}
-
}
-
-
if i run the program i displays two label boxes as well as textbox that we given in the program.when click the submit button it fires the alert box for confirmation but it also throws the runtime exceptions that i posted in last reply -
-
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 {
-
try {
-
fin = new FileInputStream(sourcefield.getText());
-
}
-
catch(FileNotFoundException e) {
-
System.out.println("Input File not found");
-
return;
-
}
-
try {
-
//fout =new FileOutputStream(destinationfield.getText());
-
String destination=destinationfield.getText();
-
destinationurl = new URL(destination);
-
connection = destinationurl.openConnection();
-
connection.setDoOutput(true);
-
//connection.connect();
-
}
-
catch (MalformedURLException e) {
-
e.printStackTrace(); // new URL() failed
-
}
-
catch (IOException e) {
-
System.out.println("unable to open");// openConnection() failed
-
}
-
/*catch(FileNotFoundException e)
-
-
{
-
System.out.println("Output File not found");
-
return;
-
}*/
-
}
-
catch(ArrayIndexOutOfBoundsException e) {
-
System.out.println(" Copy file frm to");
-
return;
-
}
-
try {
-
out = new OutputStreamWriter(connection.getOutputStream());
-
in = new BufferedReader(new InputStreamReader(fin));
-
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(IOException e) {
-
e.printStackTrace();
-
}
-
}
-
}
-
-
-
public static void main(String[] args)
-
{
-
new remotefileupload();
-
-
-
}
-
}
-
-
Are you still getting the NullPointer at the same line?
yes i get the same nullpointer exception error on the same line
if i run the program it displays
source :
destination:
when i entered d:/source.txt for source and
http://ws111/share/destination.txt for destionation and
click submit button. it fires the confirmation dialog box as success
but after that it throws that null pointer exception
yes i get the same nullpointer exception error on the same line
if i run the program it displays
source :
destination:
when i entered d:/source.txt for source and
http://ws111/share/destination.txt for destionation and
click submit button. it fires the confirmation dialog box as success
but after that it throws that null pointer exception
Can you run this one and then post the line that is reported to have the exception -
-
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();
-
-
}
-
}
-
hi,
i execute the code it not throws any error but the file is not upload at the destination pc.please review the code for further modifications -
-
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();
-
-
}
-
}
-
hi,
i execute the code it not throws any error but the file is not upload at the destination pc.please review the code for further modifications -
-
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();
-
-
}
-
}
-
Why are not you making use of the buffered reader in your code even if you declared it?
First test to see if you are reading anything at all by -
-
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());
-
String line;
-
while ((line = in.readLine()) != null) {
-
System.out.println(line);//Just read the lines and print them.
-
}
-
//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();
-
-
}
-
}
-
i tested that program it reads the content of file and displays it on the system console of the source machine -
-
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());
-
String line;
-
while ((line = in.readLine()) != null) {
-
System.out.println(line);//Just read the lines and print them.
-
}
-
//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();
-
-
}
-
}
-
i tested that program it reads the content of file and displays it on the system console of the source machine -
-
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());
-
String line;
-
while ((line = in.readLine()) != null) {
-
System.out.println(line);//Just read the lines and print them.
-
}
-
//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();
-
-
}
-
}
-
Now you want to test if you can create the file on the remote machine. Try this -
-
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));
-
;
-
String destination=destinationfield.getText();
-
destinationurl = new URL(destination);
-
connection = destinationurl.openConnection();
-
connection.setDoOutput(true);
-
//connection.connect();
-
out = new OutputStreamWriter(connection.getOutputStream());
-
fout = new FileOutputStream(destinationfield.getText());
-
String line;
-
while ((line = in.readLine()) != null) {
-
System.out.println(line);//Just read the lines and print them.
-
}
-
//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();
-
-
}
-
}
-
and see if the blank file is getting created
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Zach |
last post by:
This is all on linux using jdk1.3. My application is written in AWT,
no swing.
The application requires running it on the host machine and tunneling
the GUI back to a client. I've been doing this via an ssh session.
In the building the GUI works pretty much as if I was running it
directly from the host machine, no lags or performance problems. Over
longer distances I start to see some lagging, the GUI loses some
responsiveness, it's...
|
by: PeterB |
last post by:
Hi!
I'm using Pure ASP File Upload (http://www.asp101.com/articles/jacob/scriptupload.asp) to upload a file from a client to a server. I am testing both on a local IIS and a remote server. The welcome page has a browse button (for locating your local file), a textfield where the path is displayed, and a upload button. When clicking upload a VB ASP script is run, and the outcome is displayed on a new page.
1. On my local machine I got the...
|
by: Pat Carden |
last post by:
Hi,
We need to allow webusers to upload a file on our website (on Server3, all
servers run Server 2003, remotely hosted) and eventually save it on our SBS
Server (Server2) which is not exposed through our firewall. We have another
server (Server1) within the SBS domain that is exposed through port 80 of
the firewall on which we host some web services and images.
What is the best architecture for getting the file from the remotely...
|
by: Jen |
last post by:
I'm using Microsoft's own VB.NET FTP Example:
http://support.microsoft.com/default.aspx?scid=kb;en-us;832679
I can get the program to create directories, change directories, etc.,
but I can't get it to upload a file to the FTP server. I just get a
"Cannot connect to remote server" error after this TRY:
s = New Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)
|
by: Jobs |
last post by:
Download the JAVA , .NET and SQL Server interview with answers
Download the JAVA , .NET and SQL Server interview sheet and rate
yourself. This will help you judge yourself are you really worth of
attending interviews. If you own a company best way to judge if the
candidate is worth of it.
http://www.questpond.com/InterviewRatingSheet.zip
| |
by: Vlad |
last post by:
I am having problems using the file.create method within a function
that is called when looping through an array of filepaths.
If I call my function with a hardcoded file path --C:\Temp.txt the
function creates the file as expected.
When I loop through my array I get the error - "ArgumentException was
unhandled - Illegal characters in path"
The value "C:\Temp.txt" is the first value in the array - as it works
|
by: lPrentice |
last post by:
Hello,
After all this time, Linux file permissions still confuse me at times.
I have a Python web-based application with an file (images) upload module. The application is running on two remote servers and a local server on my development network.
The upload module works just fine when I'm uploading to my remote servers. But when I try to upload to my development server, I get a permission error.
What I don't understand is who is...
|
by: ndedhia1 |
last post by:
I was hoping you could help me out with ftp vs sftp.
Below is a method that I have that I call to ftp files from one unix box
to another in house, but soon, we will have to ftp from here to NY so we
have to start using sftp. I know that we have open ssh on our unix
boxes but was wondering how different the syntax would be, going from
ftp to sftp.
Here is a method that I have written in my java code for ftping a file
to a specific...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |