sentence
stringlengths
1
1.38k
label
stringclasses
3 values
I don't know.
o
I've never looked at the source for Derby.
o
I now know the answer to this question: No, the SQL parser for Derby isn't a separate project.
o
You will need pull it apart to use it for something other than Derby.
o
How to transfer files from one computer to another over the network using Java?
o
I need a simple application, preferably a cross-platform one, that enables sending of files between two computers.
p
It just need to accept and send the files, and show a progress bar.
o
What applications could I use or how could I write one?
o
Are you pushing or pulling the file?
o
Uploading or downloading?
o
Woof is a cool Python script that might work for you: URL_http://www.home.unix-ag.org/simon/woof.html [ URL_http://www.home.unix - ag.org/simon/woof.html] .
p
and Receiving Files** The sending and receiving of a file basically breaks down to two simple pieces of code.
p
Recieving code: CODESNIPPET_JAVA1 .
o
Sending code: CODESNIPPET_JAVA2 .
o
The sending piece of code will be ran on the computer that is sending the code when they want to send a file.
o
The receiving code needs to be put inside a loop, so that everytime someone wants to connect to the server, the server can handle the request and then go back to waiting on serverSoc.accept().
o
To allow sending files between both computers, each computer will need to run the server (receiving code) to listen for incoming files, and they will both need to run the sending code when they want to send a file.
o
Bar** The CODETERM1 in Swing is easy enough to use.
p
However, getting it to work properly and show current progress of the file transfer is slightly more difficult.
o
To get a progress bar to show up on a form only involves dropping it onto a CODETERM2 and perhaps setting CODETERM3 so hat it shows that your program is working.
o
To implement a progress bar correctly you will need to create your own implementation of a URL_http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html [CODETERM4] .
p
The Java tutorials have a good example of this in their URL_http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html [lesson-in-concurrency] .
p
This is a fairly difficult issue on its's own though.
n
I would recommend asking this in it's own question if you need more help with it.
p
@jjinguy what IP address should we put for CONNECTION_ADDRESS if the computers are not in a LAN?
o
For example, my external IP address is 1.2.3.4 but if you put 1.2.3.4 as the CONNECTION_ADDRESS, how is the router going to know which computer (within my home network) to forward the packet to?
o
@Pacerier Your router should handle the address translation for you.
o
@jjinguy, yes but how is the sender supposed to know port to send the packet to such that it will be correctly routed?
o
more on URL_http://superuser.com/questions/483033/how-does-peer-to-peer-work-over-the - internet.
o
@Pacerier I believe it should be the same port you specify on your socket.
o
Unfortunately I'm not a networking expert, so I can't really provide more info.
n
@jjinguy, Let's say Router-A sends a packet to Router-B through port 30000 (preconfigured), Router-B receives the packet, but how does it know that this packet is to be forwarded to Computer-A, and not Computer-B?
o
Sun's Java 6 includes a light-weight URL_http://java.sun.com/javase/6/docs/jre /api/net/httpserver/spec/com/sun/net/httpserver/package-summary.html [HTTP- server-API] and implementation.
p
You could fairly easily use this to serve your file, using URLConnection to obtain it.
o
I would strongly consider using FTP.
o
Apache has a FTP URL_http://commons.apach e.org/net/apidocs/org/apache/commons/net/ftp/FTPClient.html [client] and a URL_http://mina.apache.org/ftpserver/ [server] Edit: spdenne's suggestion of HTTP is also good, especially if everyone has Java 6.
p
If not, you can use something like URL_http://tjws.sourceforge.net/#download [Tiny-Java-Web-Server] .
o
yes i could.. but I wanted something as simple as possible so that beginners need not install anything... apart from installing Java which I think most people already have.
p
You're definitely going to need code over and above the JRE.
o
The only question is whether you're writing that code yourself, or using existing libraries.
o
If you write it yourself, it will probably be non-standard and you will have to maintain it yourself.
o
You can write one by using Socket programming in Java.
o
You would need to write a Server and a Client program.
o
The server would use a ServerSocket to listen for connections, and the Client would use a Socket to connect to that server on the specified port.
o
Here's a tutorial: URL_http://www.javaworld.com/jw-12-1996/jw-12-sockets.html [ URL_http://www.javaworld.com/jw-12-1996/jw-12-sockets.html ] .
o
Why reinvent the wheel?
o
Why not?
o
It's pretty quick to do, and it would be in Java.
o
I just did it !.
o
Yes, you did : ).
o
Quick to do at first (and a good learning experience), but slow to maintain for production.
n
Check out URL_http://www.rgagnon.com/javadetails/java-0542.html [this] tutorial, it's a really basic example.
o
You would probably also want to send control headers prior to the actual file being sent, containing the size of the file, filename, etc.
o
Alternatively, base it on an existing protocol, like URL_http://sourceforge.net/projects/juggle/ [this] project.
o
Thanks that's what I was looking for.
o
To transfer over a network more efficiently.
p
Take a look at URL_http://www.ibm.com/developerworks/java/library/j-zerocopy/index.html [this-article] that explains efficient data transfer through zero copy .
p
Two popular apps are "scp" and "rsync".
p
These are standard on Linux, are generally available on Unix and can be run on Windows under cygwin, although you may be able to find windows-native apps that can do it as well.
p
(PuTTY can serve as an SCP client).
o
For any sort of pc-to-pc file transfer, you need to have a listener on the destination PC.
o
This can be a daemon app (or Windows system process), or it can be a Unix-style "superserver" that's configured to load and run the actual file-copy app when someone contacts the listening port.
o
SCP and one of the rsync modes do require that there be some sort of remote login capability.
o
Rsync can also publish resources that it will handle directory.
o
Since the concept of a Windows "remote login" isn't as well- established as it is under Linux, this may be preferable.
p
Plus it limits remote access to defined sources/targets on the destination machine instead of allowing access to any (authorized) part of the filesystem.
p
Can you install FTP servers on (one of) your machines ?
o
If you can, you will just have to use a FTP client (FileZilla for example, which have a progress bar).
o
deleting folder from java.
o
i want to delete all the contents that are present in a folder which includes files and folder too.
o
I have written a java code to delete all the files but i am unable to delete the folders.
o
below is the code i am using.. CODESNIPPET_JAVA1 .
o
Please help me if i am missing something in the code??..
o
possible duplicate of [Delete files recursively in Java]( URL_http://stackoverflow.com/questions/779519/delete-files-recursively-in - java).
o
If you use URL_http://commons.apache.org/io [Apache-Commons-IO] it's a one- liner: CODESNIPPET_JAVA1 .
o
See URL_http://commons.apache.org/proper/commons-io///apidocs/org/apache/commo ns/io/FileUtils.html#deleteDirectory%28java.io.File%29 [FileUtils.deleteDirectory()] <s>Also with URL_http://code.google.com/p/guava-libraries [Guava] :</s> <s> CODETERM1 </s> This has been removed from Guava several releases ago.
o
I have something like this : CODESNIPPET_JAVA1 .
o
It could be problem with nested folders.
o
Your code deletes the folders in the order they were found, which is top-down, which does not work.
o
It might work if you reverse the folder list first.
o
But I would recommend you just use a library like Commons IO for this.
p
The javadoc for URL_http://download.oracle.com/javase/1.4.2/docs/api/java/io/F ile.html#delete%28%29 [File.delete()] public boolean delete() Deletes the file or directory denoted by this abstract pathname.
o
If this pathname a directory, then the directory must be empty in order to be deleted.
o
So a folder has to be empty or deleting it will fail.
o
Your code currently fills the folder list with the top most folder first, followed by its sub folders.
o
Since you iterrate through the list in the same way it will try to delete the top most folder before deleting its subfolders, this will fail.
o
Changing these line CODESNIPPET_JAVA1 .
o
to this CODESNIPPET_JAVA2 .
o
should cause your code to delete the sub folders first.
o
The delete operation also returns false when it fails, so you can check this value to do some error handling if necessary.
n
close - he's not using arrays but lists.
o
So the replacement code needs to to adapted in order to fit in his solution.
o
@Andreas_D thats right, fixed it.^^.
o
You're storing all (sub-) files and folder recursively in a list, but with your current code you store the parent folder _before_ you store the children.
o
And so you try to delete the folder before it is empty.
o
Try this code: CODESNIPPET_JAVA1 .
o
Try this: CODESNIPPET_JAVA1 .
o
Just wanted to tell you I loved this solution.
p
I thought it was easy to follow and simple.
p
Thanks.
o