What class that can implement file transfer in j2sdk

hi
i am doing this project that can transfer file through LAN(much like Yahoo Messenger)
is there a class in j2sdk that can implement this? how to do it?
thanks>>>>

Annie is right that if you use only j2sdk then you want to use java.net. If you want to do it an easier way you can use ftp and download open source code. There are a couple of free packages you can find at http://www.javaworld.com/javaworld/jw-04-2003/jw-0404-ftp-p2.html
If you want to use only the j2sdk then these 2 classes will give you an example of how to transfer data on the net. You need to add a lot more code to make these useful but it gives the general idea of how to open a socket and tranfser a bit of data.
Client Side
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class ClientClass {
     private final static String HOST = "10.133.5.230";
     private final static int PORT = 543;
     public void sendFile() {
          try {
               System.out.println("Entered sendFile");
               Socket socket = new Socket( HOST, PORT);
               InputStreamReader input = new InputStreamReader(socket
                         .getInputStream());
               PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
               output.println("This is a test");
               output.println("This is a test 2");
               output.println("Last line");
               output.println("ENDEND");
               socket.close();
          } catch (Exception ex) {
               ex.printStackTrace();
     public static void main(String[] args) {
          ClientClass client = new ClientClass();
          client.sendFile();
}Server Side
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerClass {
     private final static String HOST = "10.133.5.230";
     private final static int PORT = 543;
     public void getFile() {
          char[] inbuf = new char[2048];
          try {
               System.out.println("Entered getFile");
               // open server
               ServerSocket server = new ServerSocket(PORT);
               // wait for client.
               Socket client = server.accept();
               InputStreamReader inputStream = new InputStreamReader(client
                         .getInputStream());
               BufferedReader input = new BufferedReader(inputStream);
               PrintWriter output = new PrintWriter(client.getOutputStream());
               while (true) {
                    String inData = input.readLine();
                    if ((inData != null) && (inData.length() > 0)) {
                         System.out.println("got '" + inData + "'");
                         if (inData.indexOf("ENDEND") > -1) {
                              client.close();
                              server.close();
                              System.exit(0);
          } catch (Exception ex) {
               ex.printStackTrace();
     public static void main(String[] args) {
          ServerClass server = new ServerClass();
          server.getFile();
}Start the server side first and then run the client code in a separate JVM.
You will also need to add the ability to handle binary and some sort of protocol to transfer the file names and handle the exceptions much better. Doing it like this would be much more fun and challenging, with ftp it would be alot faster.

Similar Messages

  • Utility that can search files on hard disk

    I want to implement a utility in my application that can search files on the hard disk just like "find files and folsers" option in start menu of windows. What algorithm/techniques and java classes I should use.

    What algorithm/techniques and java classes I should use.
    You'll need to use recursion and the JDK 1.4.x regular expression package, java.util.regex, for pattern matching. A Java Developer's Journal article located at http://www.sys-con.com/java/article.cfm?id=854 details an implementation of a Java file search utility. Be aware that the article was written three years ago and uses a thrid-party regular expression package but it can certainly guide you in the right direction.

  • What Options I can implement for comunication PC ( lan ethernet) with SNA S

    What Options I can implement for comunication PC ( lan ethernet) with SNA Server (Lan Token Ring) :
    To see file
    thanks you,
    jj González

    What version of SNA server are you using?
    SNA server version 3 and higher support tn3270/tn3270e (for mainframe connectivity) and tn5250 (for as/400 connectivity) clients. The ms windoes telnet client does not support those protocols so you need a 3270 and/or 5250 emulator from another vendor, such as NetManage or Hummingbird.
    This assumes that you have a routed network between your workstation and the sna server.
    If your network is bridged, then you need to use an emulator that works with the native sna protocol, as the sna server supports that as well. The NetManage and Hummingbird emulators will work in this case too.
    Try to use the tn3270/tn5250 as the first choice as it does not require a bridged backbone. SNA is not a routeable protcol by default.
    Let me know if this helps.

  • I need a sample vi that can plot a transfer function given zeroes and poles (It should allow the user to input zeroes and poles). It should be done in the S domain.The user should be allowed to put poles and zeroes, with frequency

    I need a sample vi that can plot a transfer function given zeroes and poles (It should allow the user to input zeroes and poles). The user should be allowed to put poles and zeroes, with frequency. DONE IN S DOMAIN.

    I have created a VI (LabVIEW 6.1) that does what you want. Note that the poles and zeros have to be entered correctly that is in Rad/s and typically with negative real part. The VI offers you all options for lin/log frequency axis, magnitude in dB or not, phase in Radians or Degrees etc...
    The VI is written with "academic" in mind, so it is not optimized for performances but (hopefully) for clarity. I hope this will work for you.
    Attachments:
    S-Domain_Transfer_Function_from_Poles-Zeros.vi ‏167 KB

  • What adobe app can decode files with extensions bup, ifo, vob?

    What adobe app can decode files with extensions bup, ifo, vob?

    >bup, ifo
    Nothing... those are part of the file structure of a DVD
    >vob
    This is the actual video on a DVD... so Premiere Elements or Premiere Pro

  • I need a sample vi that can plot a transfer function given zeroes and poles (It should allow the user to input zeroes and poles)

    I need a sample vi that can plot a transfer function given zeroes and poles (It should allow the user to input zeroes and poles). The user should be allowed to put poles and zeroes, with frequency.

    Check the answer to your other posting
    http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=50650000000800000052A90000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0

  • XI class that can be impleented for writing a java code

    Hi ,
    I have tried to write a simple java map in Netweaver Developer Studio that will create a soap header and a few tags - there is a certain XI class you have to implement . Can some one help me out with what this class is?
    Thanks in Advance,
    Hemanthika

    hi
    chk these
    /people/venkataramanan.parameswaran/blog/2006/12/12/java-mapping-to-handle-flat-files-in-sap-xi
    /people/stefan.grube/blog/2006/10/23/testing-and-debugging-java-mapping-in-developer-studio
    rgds
    Chemmanz

  • Is there any Java componenet that can verify file types that are being uplo

    Please advise
    What i mean is that it can actually read the header of the file to determine the file type

    define "file type"
    define "uploaded"

  • What class we can use instead of "KeyGenerator" ?

    Hi all,
    I am developing a J2ME application which needs encryption. But the "KeyGenerator" class is available only in J2SE. In J2ME what we can use? Could you please tell me?
    key = KeyGenerator.getInstance(algorithm).generateKey();

    this link will help you and search for bouncy castle api ...

  • [GeForce 6] What's that sw20.exe file in msi nvidia drivers ?

    Hello,
    I have recently downloaded et installed msi nvidia drivers for my NX6600 GT (agp and vivo). No problem. But i discovered this morning that a sw20.exe file was launched by the registry  at windows start up. It took me a long time to discover that this file had been installed with the drivers.
    So, here is my question : what's the use of this file ?
    Thanks for the answers et sorry for my poor english.

    Quote from: BOSSKILLER on 28-July-06, 16:33:48
    uf yep 15 June 05  but just seen it 
    btw Glenn what is wrong with your fish(avatar) not swim all the time making rest sometimes, is he/she tired or also hot? or just my pc is lagging
    It was eaten by the giant Panda you see now.....

  • What technology that can be used for the creation of Need Definition?

    Being on SAP SRM 4.0, we currently have a requirement for creation of Need Definition( Basically a build up for the contract ). Need being collected from the Backend systems need to be validated and approved by Buyers & Lead Buyers in the SRM system.
    Technically, this task is broken down to below tasks.
    1) Creation of need definition screen - Basically a template where a need can be created with Items, Sub Items and other related information
    2) Selection Screen for Buyers and Lead Buyers - This enables the the Buyers to select the Need Definition assigned to them based on the status. 
    3) Report - List of all the Need Definition( Item and Sub Item)satisfying the selection of step 2. with the possibility to navigate to the Need Definition screen ( Step 1) upon selection.
    Now the question is,
    what technology is recommended for the above Tasks? We thought it would be BSP but do you guys have any suggestions...
    Do we have any issues in displaying the report in BSP? please let me know
    Remember we are version 4.0 of SRM.
    Thanks in Advance..
    Mohan.

    You can use conditional styles to address specific browser issues (this is more than likely the markup you noticed).
    Here's a good guide:
    http://www.quirksmode.org/css/condcom.html

  • JAVA file transfer

    Hello,
    I am currently working on an application that is to create a multipart response to the client.
    The first part of this response is to send an xml descriptor file, and the second part of this response is to send a content object (audio or image).
    The xml descriptor file needs to be generated dynamically according to the http headers received from the client and then sent to the client. How should I go about doing this? Just write everything I would in the xml file in a String, convert the String into bytes [] and write it to the response output stream? or create an actual temporary file on the hard disk, and then send that file to the output stream? I am new to JAVA so, really do not know the best approach to take.
    Note: I am prohibited due to some company policies to generate XML files using JAVAX or similar technologies.
    Any help would be appreciated.
    Thanks,
    Saurabh

    so r u saying that i can implement File transfer using only client APIs?
    but cudnt find it.. so plz explain a little. http://www.catb.org/~esr/faqs/smart-questions.html
    How To Ask Questions The Smart Way
    Eric Steven Raymond
    Thyrsus Enterprises
    Copyright © 2001,2006 Eric S. Raymond, Rick Moen
    Write in clear, grammatical, correctly-spelled language
    We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.
    So expressing your question clearly and well is important. If you can't be bothered to do that, we can't be bothered to pay attention. Spend the extra effort to polish your language. It doesn't have to be stiff or formal — in fact, hacker culture values informal, slangy and humorous language used with precision. But it has to be precise; there has to be some indication that you're thinking and paying attention.
    Spell, punctuate, and capitalize correctly. Don't confuse “its” with “it's”, “loose” with “lose”, or “discrete” with “discreet”. Don't TYPE IN ALL CAPS; this is read as shouting and considered rude. (All-smalls is only slightly less annoying, as it's difficult to read. Alan Cox can get away with it, but you can't.)
    More generally, if you write like a semi-literate b o o b you will very likely be ignored. So don't use instant-messaging shortcuts. Spelling "you" as "u" makes you look like a semi-literate b o o b to save two entire keystrokes. Worse: writing like a l33t script kiddie hax0r is the absolute kiss of death and guarantees you will receive nothing but stony silence (or, at best, a heaping helping of scorn and sarcasm) in return.

  • Can't find how to shut off File Transfer Mode with...

    I've spent the better part of two hours searching the Internet for information on how to turn off File Transfer Mode since my phone started refusing to connect to my home computer, today.
    The pdf user's guide doesn't say how to find it.  I've been digging through the menu on the phone trying to find anything that resembles File Transfer Mode so I can click it off.
    The other FAQ and discussion groups I've located are irrelavent as the information they contain doesn't transfer to my Nokia 820 (they suggest options which don't exist on my phone).
    Please, where does one start looking for File Transfer Mode on this phone so they can shut it off, and why isn't that information printed in the troubleshooting documents and self help files for these phones?
    I connect through the USB cable to my PC.  I have downloaded and installed Nokia PC Suite v.7.1.180.94 this morning in hopes that it would fix the connectivity problem, but unless I can get File Transfer Mode shut off somehow, my new phone's going to wind up being useless.
    Nokia Lumia 820, Windows 8 phone
    HP Pavilion Slimline s52021, Windows 7 Home

    have you searched these forums and tried a soft reset (pressing the volume down and power buttons together until the phone vibrates)? Bear in mind that no, Nokia Suite, or Nokia PC Suite do not work with Windows Phone 8 devices at all, only the Windows Phone app does.
    See if other devices connect to your PC, and try other USB ports.

  • .desktop file, what is that?

    Seeing packages around I see many put .desktop files in /usr/share/application, what is that?

    .desktop files is freedesktop standard shortcuts. GNOME, KDE, XFCE and some other software use them to provide you nice menu with apps installed

  • IM System File Transfer through NAT

    Hi, i have operational IM system with server and client and i want to implement file transfer. Not that it was any difficult but i want to make it server independent to relieve it.
    What i want to is establish direct connection between transferring clients. The problem is, how to deal with guys behind NAT.
    I have seen many topics here and on other forums dealing with it but they were direct questions in advanced development of this issue and i want to ask if there is any way to do it without reconfiguring the client routers (some of them behind IPS's Gateway and owning own wifi router) or not. I would like to know your ideas or experiences on this matter how start with this or where to look for it. I certainly dont want to do some ip tunnelling through RMI or similar.
    Regards ~

    When connecting possibly NATed peers, there are three main scenarious:
    * All peers have a public IP, no NAT anywhere: Easy, simply connect
    * At least on peer has a public IP, no NAT, some or all other peers are NATed/don't have public IP: public peer acts as a server of kind/hub
    * Everyone is NATed: not it's getting very, very tricky.
    Especially for the third kind you will need to implement several different techniques.
    Keywords to google for are UPNP (to reconfigure the router for port forwarding) and NAT piercing (fooling both routers to think it's an outgoing connection).
    Good luck.

Maybe you are looking for

  • Hi there,i have a powerbook G4 1GB,cpu speed 1.5 ghz,512KB,running panther 10.3.3.Could this be upgraded to tiger or leopard?thank you

    Hi I have a powerbook g4 1.5 ghz powerpc g4 1 gb ddr 512 kb Is running panther 10.3.3 Could this be upgraded to tiger or leopard Thank you

  • Account Expired

    We are using the Adobe Connect Host service and payment is by credit card. Before, we did not receive any payment problem e-mail from Adobe. Today, suddently, when we want to login and start up a meeting, it shows "Your Account Has Expired"!!! We can

  • X301 and MBR

    I am running WinXP-SP3 on a X301. For the first year it was working fine with AHCI mode activated in the BIOS and a SSD SATA 64Gb. However, every now and then I lose the MBR and I have to repair it with XP installation disk. If I deactivate AHCI and

  • Help! Touch tracker stopped working!

    Hello My touch tracker has stopped working on my Blackberry Curve 9300 3G I cant scroll or move round Can you help? Thanks

  • Version management - pretty printer problem.

    I have got a change request to change program. Around 20 developers changed this program. I have changed the program. BUT BY MISTAKE I HAVE PRESSED PRETTY PRINTER button. AS a result ...later to while checking version managenment,  my program won't s