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
if i run the program i got the Exception "input file not found" -
-
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();
-
-
}
-
}
-
if i run the program i got the Exception "input file not found" -
-
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();
-
-
}
-
}
-
What had you specified as the destination?
Run this and check the stack trace to see which file was not found. -
-
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");
-
e.printStackTrace();
-
}
-
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'm begginning to think we may need a Socket for this
i got the following error:
Input File not found
java.io.FileNot FoundException: http:\ws111\Sha re\source.txt (The filename, direc
tory name, or volume label syntax is incorrect)
at java.io.FileOut putStream.open( Native Method)
at java.io.FileOut putStream.<init >(FileOutputStr eam.java:179)
at java.io.FileOut putStream.<init >(FileOutputStr eam.java:70)
at remotefileuploa d.actionPerform ed(remotefileup load.java:60)
at javax.swing.Abs tractButton.fir eActionPerforme d(AbstractButto n.java:17
86)
at javax.swing.Abs tractButton$For wardActionEvent s.actionPerform ed(Abstra
ctButton.java:1 839)
at javax.swing.Def aultButtonModel .fireActionPerf ormed(DefaultBu ttonModel
.java:420)
at javax.swing.Def aultButtonModel .setPressed(Def aultButtonModel .java:258
)
at javax.swing.pla f.basic.BasicBu ttonListener.mo useReleased(Bas icButtonL
istener.java:24 5)
at java.awt.Compon ent.processMous eEvent(Componen t.java:5100)
at java.awt.Compon ent.processEven t(Component.jav a:4897)
at java.awt.Contai ner.processEven t(Container.jav a:1569)
at java.awt.Compon ent.dispatchEve ntImpl(Componen t.java:3615)
at java.awt.Contai ner.dispatchEve ntImpl(Containe r.java:1627)
at java.awt.Compon ent.dispatchEve nt(Component.ja va:3477)
at java.awt.Lightw eightDispatcher .retargetMouseE vent(Container. java:3483
)
at java.awt.Lightw eightDispatcher .processMouseEv ent(Container.j ava:3198)
at java.awt.Lightw eightDispatcher .dispatchEvent( Container.java: 3128)
at java.awt.Contai ner.dispatchEve ntImpl(Containe r.java:1613)
at java.awt.Window .dispatchEventI mpl(Window.java :1606)
at java.awt.Compon ent.dispatchEve nt(Component.ja va:3477)
at java.awt.EventQ ueue.dispatchEv ent(EventQueue. java:480)
at java.awt.EventD ispatchThread.p umpOneEventForH ierarchy(EventD ispatchTh
read.java:201)
at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(EventDis patchThre
ad.java:151)
at java.awt.EventD ispatchThread.p umpEvents(Event DispatchThread. java:145)
at java.awt.EventD ispatchThread.p umpEvents(Event DispatchThread. java:137)
at java.awt.EventD ispatchThread.r un(EventDispatc hThread.java:10 0)
Actually we need to send the file to remote pc by specifing their path in destination textbox.if we use socket then we should open the socket from client side also and we install client program on all the client machine we not need copy the file in all client machine,so we need different solution other then sockets to accept datai.e dynamically the destination pc accept the data
i got the following error:
Input File not found
java.io.FileNot FoundException: http:\ws111\Sha re\source.txt (The filename, direc
tory name, or volume label syntax is incorrect)
at java.io.FileOut putStream.open( Native Method)
at java.io.FileOut putStream.<init >(FileOutputStr eam.java:179)
at java.io.FileOut putStream.<init >(FileOutputStr eam.java:70)
at remotefileuploa d.actionPerform ed(remotefileup load.java:60)
at javax.swing.Abs tractButton.fir eActionPerforme d(AbstractButto n.java:17
86)
at javax.swing.Abs tractButton$For wardActionEvent s.actionPerform ed(Abstra
ctButton.java:1 839)
at javax.swing.Def aultButtonModel .fireActionPerf ormed(DefaultBu ttonModel
.java:420)
at javax.swing.Def aultButtonModel .setPressed(Def aultButtonModel .java:258
)
at javax.swing.pla f.basic.BasicBu ttonListener.mo useReleased(Bas icButtonL
istener.java:24 5)
at java.awt.Compon ent.processMous eEvent(Componen t.java:5100)
at java.awt.Compon ent.processEven t(Component.jav a:4897)
at java.awt.Contai ner.processEven t(Container.jav a:1569)
at java.awt.Compon ent.dispatchEve ntImpl(Componen t.java:3615)
at java.awt.Contai ner.dispatchEve ntImpl(Containe r.java:1627)
at java.awt.Compon ent.dispatchEve nt(Component.ja va:3477)
at java.awt.Lightw eightDispatcher .retargetMouseE vent(Container. java:3483
)
at java.awt.Lightw eightDispatcher .processMouseEv ent(Container.j ava:3198)
at java.awt.Lightw eightDispatcher .dispatchEvent( Container.java: 3128)
at java.awt.Contai ner.dispatchEve ntImpl(Containe r.java:1613)
at java.awt.Window .dispatchEventI mpl(Window.java :1606)
at java.awt.Compon ent.dispatchEve nt(Component.ja va:3477)
at java.awt.EventQ ueue.dispatchEv ent(EventQueue. java:480)
at java.awt.EventD ispatchThread.p umpOneEventForH ierarchy(EventD ispatchTh
read.java:201)
at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(EventDis patchThre
ad.java:151)
at java.awt.EventD ispatchThread.p umpEvents(Event DispatchThread. java:145)
at java.awt.EventD ispatchThread.p umpEvents(Event DispatchThread. java:137)
at java.awt.EventD ispatchThread.r un(EventDispatc hThread.java:10 0)
Actually we need to send the file to remote pc by specifing their path in destination textbox.if we use socket then we should open the socket from client side also and we install client program on all the client machine we not need copy the file in all client machine,so we need different solution other then sockets to accept datai.e dynamically the destination pc accept the data
I think this is the proper way to do it. http://java.sun.com/docs/books/tutor...ngWriting.html
Try it and tell me how it goes
in that also it need one more program that should run on the server and program run on the client.but we not need such servlet implementation we need simple java program
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: 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...
| |