File transfer via socket problem (with source code)

I have a problem with this simple client/server filetransfer program. When I run it, only half the file is transfered via the net? Can someone point out to me why this is happening?
Client:
import java.net.*;
import java.io.*;
     public class Client {
     public static void main(String[] args) {
          // IPadressen til server
          String host = "127.0.0.1";
          int port = 4545;
          //Lager streams
          BufferedInputStream fileIn = null;
          BufferedOutputStream out = null;
          // Henter filen vi vil sende over sockets
          File file = new File("c:\\temp\\fileiwanttosend.jpg");
// Sjekker om filen fins
          if (!file.exists()) {
          System.out.println("File doesn't exist");
          System.exit(0);
          try{
          // Lager ny InputStream
          fileIn = new BufferedInputStream(new FileInputStream(file));
          }catch(IOException eee) {System.out.println("Problem, kunne ikke lage fil"); }
          try{
          // Lager InetAddress
          InetAddress adressen = InetAddress.getByName(host);
          try{
          System.out.println("- Lager Socket..........");
          // �pner socket
          Socket s = new Socket(adressen, port);
          System.out.println("- Socket klar.........");
          // Setter outputstream til socket
          out = new BufferedOutputStream(s.getOutputStream());
          // Leser buffer inn i tabell
          byte[] buffer = new byte[1024];
          int numRead;
          while( (numRead = fileIn.read(buffer)) >= 0) {
          // Skriver bytes til OutputStream fra 0 til totalt antall bytes
          System.out.println("Copies "+fileIn.read(buffer)+" bytes");
          out.write(buffer, 0, numRead);
          // Flush - sender fil
          out.flush();
          // Lukker OutputStream
          out.close();
          // Lukker InputStrean
          fileIn.close();
          // Lukker Socket
          s.close();
          System.out.println("File is sent to: "+host);
          catch (IOException e) {
          }catch(UnknownHostException e) {
          System.err.println(e);
Server:
import java.net.*;
import java.io.*;
public class Server {
     public static void main(String[] args) {
// Portnummer m� v�re det samme p� b�de klient og server
int port = 4545;
     try{
          // Lager en ServerSocket
          ServerSocket server = new ServerSocket(port);
          // Lager to socketforbindelser
          Socket forbindelse1 = null;
          Socket forbindelse2 = null;
     while (true) {
     try{
          forbindelse1 = server.accept();
          System.out.println("Server accepts");
          BufferedInputStream inn = new BufferedInputStream(forbindelse1.getInputStream());
          BufferedOutputStream ut = new BufferedOutputStream(new FileOutputStream(new File("c:\\temp\\file.jpg")));
          byte[] buff = new byte[1024];
          int readMe;
          while( (readMe = inn.read(buff)) >= 0) {
          // Skriver filen til disken ut fra input stream
          ut.write(buff, 0, readMe);
          // Lukker ServerSocket
          forbindelse1.close();
          // Lukker InputStream
          inn.close();
          // flush - sender data ut p� nettet
          ut.flush();
          // Lukker OutputStream
          ut.close();
          System.out.println("File received");
          }catch(IOException e) {System.out.println("En feil har skjedd: " + e.getMessage());}
          finally {
               try {
               if (forbindelse1 != null) forbindelse1.close();
               }catch(IOException e) {}
}catch(IOException e) {
System.err.println(e);
}

Hi!!
The problem is at this line:
System.out.println("Copies "+fileIn.read(buffer)+" bytes");
Just comment out this line of code and see the difference. This line of code causes another "read" statement to be executed, but you are writing only the data read from the first read statement which causes approximately half the file to be send to the server.

Similar Messages

  • Fast file transfer via sockets

    Hi,
    I have made little program that sends files via lan to my other computer using sockets (ServerSocket and Socket). When I code my program to use only FileInputStream and FileOutputStream throught the sockets I get only speed about 100Kbs even when I run them in localhost.
    I would really like to have examples of faster way to send and receive files throught sockets? Any samples using buffers or compressing data would be very nice. Thank you very much in advance!
    Sincerely,
    Lauri Lehtinen

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    * FileServer.java
    * Created on January 18, 2005, 2:21 PM
    * @author  Ian Schneider
    public class FileServer {
        static class Server {
            Socket client;
            public Server() throws Exception {
                ServerSocket s = new ServerSocket(12345);
                while (true) {
                    client = s.accept();
                    File dest = new File(System.getProperty("java.io.tmpdir"),"transfer.tmp");
                    InputStream data = client.getInputStream();
                    OutputStream out = new FileOutputStream(dest);
                    byte[] bytes = new byte[1024];
                    int l = 0;
                    int cnt = 0;
                    long time = System.currentTimeMillis();
                    while ( (l = data.read(bytes)) >= 0) {
                        cnt += l;
                        out.write(bytes,0, l);
                    int kb = cnt / 1024;
                    int sec = (int) (System.currentTimeMillis() - time) / 1000;
                    System.out.println("transfered " + kb/sec);
                    out.flush();
                    out.close();
                    client.close();
        static void writeToServer(String fileName) throws Exception {
            Socket s = new Socket("localhost",12345);
            OutputStream out = s.getOutputStream();
            FileInputStream in = new FileInputStream(fileName);
            byte[] bytes = new byte[1024];
            int l = 0;
            while ( (l = in.read(bytes)) >= 0) {
                out.write(bytes,0,l);
            out.flush();
            out.close();
            in.close();
        public static final void main(String[] args) throws Exception {
            if (args[0].equals("server")) {
                new Server();
            } else {
                writeToServer(args[1]);
    }You may see improvements by buffering these. I didn't bother testing.

  • Facing problem with the code for sending an .xls attachment via email, a field value contains leading zeros but excel automatically removes these from display i.e. (00444 with be displayed as 444).kindly guide .

    Facing problem with the code for sending an .xls attachment via email, a field value contains leading zeros but excel automatically removes these from display i.e. (00444 with be displayed as 444).kindly guide .

    Hi Chhayank,
    the problem is not the exported xls. If you have a look inside with Notepad or something like that, you will see that your leading zeros are exported correct.Excel-settings occurs this problem, it is all about how to open the document. If you use the import-assistant you will have no problems because there are options available how to handle the different columns.
    Another solution might be to get familiar with ABAP2XLS-Project. I got in my mind, that there is a method implemented, that will help you solving this problem. But that is not a five minute job
    ~Florian

  • What is the problem with the code?

    Hello, the following is a segment of code that I have written recently:
            IF DATA+1(5) <> TEXT-035.
              CATCH SYSTEM-EXCEPTIONS WEIRD_ERROR = 4
                                     OTHERS = 8.
                END CATCH.
              ENDIF.
    When I tried to compile the code, it says:
    Unable to interpret "SYSTEM-EXCEPTIONS". Possible causes: Incorrect spelling or comma error.          
    May I know where is the problem with this code? Thanks a lot!
    Regards,
    Anyi

    Here is a list of the system exceptions.
    Alphabetical List of Catchable Runtime Errors
    ,,ADDF_INT_OVERFLOW
    Overflow in addition with type I ( ADD ... UNTIL / ADD ... FROM ... TO)
    ,,ASSIGN_CASTING_ILLEGAL_CAST
    The offset and type of the source field and the target type do not match exactly in the components that are strings, tables, or references.
    ,,ASSIGN_CASTING_UNKNOWN_TYPE
    The type specified at runtime is unknown.
    ,,BCD_FIELD_OVERFLOW
    Overflow in conversion or arithmetic operations (type P with specified length)
    ,,BCD_OVERFLOW
    Overflow in conversion or arithmetic operation (type P)
    ,,BCD_ZERODIVIDE
    Division by 0 (type P)
    ,,CALL_METHOD_NOT_IMPLEMENTED
    Call of a non-implemented interface method
    ,,COMPUTE_ACOS_DOMAIN
    Invalid call of mathematical function ACOS
    ,,COMPUTE_ASIN_DOMAIN
    Invalid call of mathematical function ASIN
    ,,COMPUTE_ATAN_DOMAIN
    Invalid call of mathematical function ATAN
    ,,COMPUTE_BCD_OVERFLOW
    Overflow in arithmetic operation (all operands type P)
    ,,COMPUTE_COSH_DOMAIN
    Invalid call of mathematical function COSH
    ,,COMPUTE_COSH_OVERFLOW
    Overflow in mathematical function COSH
    ,,COMPUTE_COS_DOMAIN
    Invalid call of mathematical function COS
    ,,COMPUTE_COS_LOSS
    Result of COS function is inexact
    ,,COMPUTE_EXP_DOMAIN
    Invalid call of mathematical function EXP
    ,,COMPUTE_EXP_RANGE
    Over- or underflow in mathematical function EXP
    ,,COMPUTE_FLOAT_DIV_OVERFLOW
    Overflow in division (type F)
    ,,COMPUTE_FLOAT_MINUS_OVERFLOW
    Overflow in subtraction (type F)
    ,,COMPUTE_FLOAT_PLUS_OVERFLOW
    Overflow in addition (type F)
    ,,COMPUTE_FLOAT_TIMES_OVERFLOW
    Overflow in multiplication (type F)
    ,,COMPUTE_FLOAT_ZERODIVIDE
    Division by 0 (type F)
    ,,COMPUTE_INT_ABS_OVERFLOW
    Integer overflow when calculating the absolute value
    ,,COMPUTE_INT_DIV_OVERFLOW
    Integer overflow in division
    ,,COMPUTE_INT_MINUS_OVERFLOW
    Integer overflow in subtraction
    ,,COMPUTE_INT_PLUS_OVERFLOW
    Integer overflow in addition
    ,,COMPUTE_INT_TIMES_OVERFLOW
    Integer overflow in multiplication
    ,,COMPUTE_INT_ZERODIVIDE
    Division by 0 (type I)
    ,,COMPUTE_LOG10_ERROR
    Invalid call of the mathematical function LOG10
    ,,COMPUTE_LOG_ERROR
    Invalid call of the mathematical function LOG
    ,,COMPUTE_MATH_DOMAIN
    Invalid call of a mathematical function
    ,,COMPUTE_MATH_ERROR
    Error executing a mathematical function
    ,,COMPUTE_MATH_LOSS
    Result of a mathematical function is inexact
    ,,COMPUTE_MATH_OVERFLOW
    Overflow of a mathematical function
    ,,COMPUTE_MATH_UNDERFLOW
    Underflow in a mathematical function
    ,,COMPUTE_POW_DOMAIN
    Invalid argument when raising powers
    ,,COMPUTE_POW_RANGE
    Over- or underflow when raising powers
    ,,COMPUTE_SINH_DOMAIN
    Invalid call of the mathematical function SINH
    ,,COMPUTE_SINH_OVERFLOW
    Overflow in the mathematical function SINH
    ,,COMPUTE_SIN_DOMAIN
    Invalid call of the mathematical function SIN
    ,,COMPUTE_SIN_LOSS
    Result of the function SIN is inexact
    ,,COMPUTE_SQRT_DOMAIN
    Invalid call of the mathematical function SQRT
    ,,COMPUTE_TANH_DOMAIN
    Invalid call of the mathematical function TANH
    ,,COMPUTE_TAN_DOMAIN
    Invalid call of the mathematical function TAN
    ,,COMPUTE_TAN_LOSS
    Result of the function TAN is inexact
    ,,CONNE_IMPORT_WRONG_COMP_LENG
    Import error: A component in a structured type in the dataset has an incorrect length
    ,,CONNE_IMPORT_WRONG_COMP_TYPE
    Import error: A component of a structured type in the dataset has an incorrect length
    ,,CONNE_IMPORT_WRONG_FIELD_LENG
    Import error: A field in the dataset has an incorrect length
    ,,CONNE_IMPORT_WRONG_FIELD_TYPE
    Import error: A field in a dataset has the wrong type
    ,,CONNE_IMPORT_OBJECT_TYPE
    Import error: Type conflict between simple and structured data types
    ,,CONNE_IMPORT_WRONG_STRUCTURE
    Import error: Type conflict between structured objects
    ,,CONVT_HEX_CONFLICT
    Conversion conflict (Type X)
    ,,CONVT_NO_NUMBER
    Value for conversion cannot be interpreted as a number
    ,,CONVT_OVERFLOW
    Overflow in conversion (all types except type P)
    ,,CREATE_DATA_NOT_ALLOWED_TYPE
    The statement CREATE DATA cannot be executed with a generic type.
    ,,CREATE_DATA_UNKNOWN_TYPE
    The statement CREATE DATA cannot be executed with an unknown type.
    ,,CREATE_OBJECT_CLASS_ABSTRACT
    Attempt to instantiate an abstract class.
    ,,CREATE_OBJECT_CLASS_NOT_FOUND
    The class specified with a dynamic CREATE OBJECT was not found.
    ,,CREATE_OBJECT_CREATE_PRIVATE
    Attempt to create an object of a class defined as 'CREATE PRIVATE'.
    ,,CREATE_OBJECT_CREATE_PROTECTED
    Attempt to create an object of a class defined as 'CREATE PROTECTED'.
    ,,DATA_LENGTH_NEGATIVE
    Invalid subfield access: Negative length
    ,,DATA_LENGTH_0
    Invalid subfield access: Length 0
    ,,DATA_LENGTH_TOO_LARGE
    Invalid subfield access: Length too large
    ,,DATA_OFFSET_NEGATIVE
    Invalid subfield access: Negative offset
    ,,DATA_OFFSET_TOO_LARGE
    Invalid subfield access: Offset too large
    ,,DATA_OFFSET_LENGTH_TOO_LARGE
    Invalid subfield access: Offset + length too large
    ,,DATA_OFFSET_LENGTH_NOT_ALLOWED
    Invalid subfield access: Type not appropriate
    ,,DATASET_CANT_CLOSE
    Unable to close file. There may be no space left in the file system
    ,,DATASET_CANT_OPEN
    Unable to open file
    ,,DATASET_NO_PIPE
    The FILTER addition to the OPEN DATASET statement is not supported on the current operating system
    ,,DATASET_READ_ERROR
    Error reading a file
    ,,DATASET_TOO_MANY_FILES
    Maximum number of open files exceeded
    ,,DATASET_WRITE_ERROR
    Error writing to a file
    ,,DYN_CALL_METH_CLASSCONSTRUCTOR
    Attempt to call the class constructor
    ,,DYN_CALL_METH_CLASS_ABSTRACT
    Attempt to call an abstract method
    ,,DYN_CALL_METH_CLASS_NOT_FOUND
    Attempt to call a method of a non-existent class
    ,,DYN_CALL_METH_CONSTRUCTOR
    Attempt to call the instance constructor
    ,,DYN_CALL_METH_EXCP_NOT_FOUND
    Attempt to catch an unknown exception
    ,,DYN_CALL_METH_NOT_FOUND
    Attempt to call an unknown method
    ,,DYN_CALL_METH_NOT_IMPLEMENTED
    Attempt to call a method that has not been implemented yet
    ,,DYN_CALL_METH_NO_CLASS_METHOD
    Attempt to call an instance method via a class
    Attempt to pass a parameter with an incorrect parameter type
    ,,DYN_CALL_METH_PARAM_LITL_MOVE
    Attempt to pass a constant actual parameter to a formal EXPORTING, CHANGING or RETURNING parameter
    ,,DYN_CALL_METH_PARAM_MISSING
    An obligatory parameter was not supplied.
    ,,DYN_CALL_METH_PARAM_NOT_FOUND
    Attempt to pass an unknown parameter
    ,,DYN_CALL_METH_PARAM_TAB_TYPE
    Attempt to pass a parameter with an incorrect table type
    ,,DYN_CALL_METH_PARAM_TYPE
    Attempt to pass a parameter with an incorrect type
    ,,DYN_CALL_METH_PARREF_INITIAL
    An initial data reference was passed for an mandatory parameter.
    ,,DYN_CALL_METH_PRIVATE
    Attempt to call a private method from outside
    ,,DYN_CALL_METH_PROTECTED
    Attempt to call a protected method from outside
    ,,DYN_CALL_METH_REF_IS_INITIAL
    Attempt to call a method with an initial reference
    ,,EXPORT_BUFFER_NO_MEMORY
    The EXPORT data cluster is too large for the application buffer
    ,,EXPORT_DATASET_CANNOT_OPEN
    The IMPORT/EXPORT statement could not open the file
    ,,EXPORT_DATASET_WRITE_ERROR
    The EXPORT statement could not write to the file
    ,,GENERATE_SUBPOOL_DIR_FULL
    The system cannot generate any more temporary subroutine pools
    ,,IMPORT_ALIGNMENT_MISMATCH
    Import error: Same sequence of components, but with type conflict or different alignment in structured data types
    ,,IMPORT_TYPE_MISMATCH
    Import error: Only with IMPORT...FROM MEMORY | FROM SHARED BUFFER...
    ,,MOVE_CAST_ERROR
    Type conflict when assigning between object and interface references (only MOVE...?TO... or operator ?=)
    ,,OPEN_DATASET_NO_AUTHORITY
    No authorizatino to access the file
    ,,OPEN_PIPE_NO_AUTHORITY
    No authorization to access the file (OPEN DATASET...FILTER...).
    ,,PERFORM_PROGRAM_NAME_TOO_LONG
    Invalid program name with PERFORM statement
    ,,RMC_COMMUNICATION_FAILURE
    Communication error with Remote Method Call
    ,,RMC_INVALID_STATUS
    Status error with Remote Method Call
    ,,RMC_SYSTEM_FAILURE
    System error with Remote Method Call
    ,,STRING_LENGTH_NEGATIVE
    Invalid access with negative length to a string
    ,,STRING_LENGTH_TOO_LARGE
    Invalid access to a string (length too large)
    ,,STRING_OFFSET_NEGATIVE
    Invalid access with negative offset to a string
    ,,STRING_OFFSET_TOO_LARGE
    Invalid access to a string (offset too large)
    ,,STRING_OFFSET_LENGTH_TOO_LARGE
    Invalid access to a string (offset + length too large)
    ,,TEXTENV_CODEPAGE_NOT_ALLOWED
    Character set is not released in the system (SET LOCALE...)
    ,,TEXTENV_INVALID
    Error setting the text environment (SET LOCALE...)
    ,,TEXTENV_KEY_INVALID
    With SET LOCALE...: Value of LANGUAGE, COUNTRY or MODIFIER that is not allowed in the system.
    ,,TEXTENV_LANGUAGE_NOT_ALLOWED
    With SET LOCALE...: Invalid value of the LANGUAGE addition.
    What version of SAP are you on?   If on a newer version you may be able to create your own exception class.
    Regards,
    Rich Heilman

  • Problem with php code. Please help!

    Hello!
    I'm using the following syntax to bring content into my
    websites' layout template:
    Code:
    <?php //check in the root folder first
    if(file_exists('./' . $pagename . '.php'))
    include './' . $pagename . '.php';
    //if it wasn't found in the root folder then check in the
    news folder
    elseif(file_exisits('./news/' . $filename . '.php'))
    include './news/' . $pagename . '.php';
    // if it couldn't be found display message
    else
    echo $pagename . '.php could not be found in either the root
    folder or the news folder!';
    } ?>
    What it's essentially saying is, if you can't find the .php
    file in the _root folder, look for it in the /news/ folder.
    It works perfectly if loading something from the _root folder
    but I get an error if I need to bring something from the /news/
    folder.
    Can anyone see any potential problems with my code?
    Thank you very much and I hope to hear from you.
    Take care,
    Mark

    I've never seen the code written like that before, but I'm
    assuming it's
    legal?
    Perhaps try:
    <?php
    $newsroot = $_SERVER['DOCUMENT_ROOT']."/news";
    if (!file_exists("$pagename.php")) {
    elseif (!file_exists("$newsroot/$pagename.php")) {
    else
    Or the other thing you can try is replacing the elseif
    statement with:
    elseif (!file_exists("news/$pagename.php"))
    If not - I'm sure Gary will be on here soon...
    Shane H
    [email protected]
    http://www.avenuedesigners.com
    =============================================
    Proud GAWDS Member
    http://www.gawds.org/showmember.php?memberid=1495
    Delivering accessible websites to all ...
    =============================================
    "Spindrift" <[email protected]> wrote in
    message
    news:e5mled$272$[email protected]..
    > Hello!
    >
    > I'm using the following syntax to bring content into my
    websites' layout
    > template:
    >
    > Code:
    >
    > <?php //check in the root folder first
    > if(file_exists('./' . $pagename . '.php'))
    > {
    > include './' . $pagename . '.php';
    > }
    > //if it wasn't found in the root folder then check in
    the news folder
    > elseif(file_exisits('./news/' . $filename . '.php'))
    > {
    > include './news/' . $pagename . '.php';
    > }
    > // if it couldn't be found display message
    > else
    > {
    > echo $pagename . '.php could not be found in either the
    root folder or
    > the
    > news folder!';
    > } ?>
    >
    > What it's essentially saying is, if you can't find the
    .php file in the
    > _root
    > folder, look for it in the /news/ folder.
    >
    > It works perfectly if loading something from the _root
    folder but I get an
    > error if I need to bring something from the /news/
    folder.
    >
    > Can anyone see any potential problems with my code?
    >
    > Thank you very much and I hope to hear from you.
    >
    > Take care,
    >
    > Mark
    >

  • Save weblog with source code

    Hi,
    Does anyone an easy way of downloading weblogs with source codes?
    If I select all/copy&paste into Microsoft Word 2000 (SP3), the source codes get this "nice" frame, where they are scrollable. When I save it and open it again, the source code is not scrollable, so I can only diplay the part of it:-(
    Is there a way of avoid it from my side?
    I know from the composer side it can be done, as foir example Sergei did in his weblog:
    /people/sergey.korolev/blog/2005/03/14/the-time-for-me-to-have-a-badi-of-my-own
    Or is it planned to change this annoying scrollable code frame?
    Thanks,
    Peter

    Printing of Weblogs
    Take a look at that thread for some possible help.
    As for the "annoying scrollable code frame" well we've been doing it for awhile now and nobody has been complaining too loudly.
    If the thought of everyone is to be rid of the textarea then I suppose I wouldn't have a problem using the styles instead.

  • Please tell me what is the problem with this code

    Hai,
    Iam new to Swings. can any one tell what is the problem with this code. I cant see those controls on the frame. please give me the suggestions.
    I got the frame ,but the controls are not.
    this is the code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ex2 extends JFrame
    JButton b1;
    JLabel l1,l2;
    JPanel p1,p2;
    JTextField tf1;
    JPasswordField tf2;
    public ex2()
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setTitle("Another example");
    setSize(500,500);
    setVisible(true);
    b1=new JButton(" ok ");
    p1=new JPanel();
    p1.setLayout(new GridLayout(2,2));
    p2=new JPanel();
    p2.setLayout(new BorderLayout());
    l1=new JLabel("Name :");
    l2=new JLabel("Password:");
    tf1=new JTextField(15);
    tf2=new JPasswordField(15);
    Container con=getContentPane();
    con.add(p1);
    con.add(p2);
    public static void createAndShowGUI()
    ex2.setDefaultLookAndFeelDecorated(true);
    public static void main(String ar[])
    createAndShowGUI();
    new ex2();
    }

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ex2 extends JFrame
        JButton b1;
        JLabel l1,l2;
        JPanel p1,p2;
        JTextField tf1;
        JPasswordField tf2;
        public ex2()
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setTitle("Another example");
            b1=new JButton(" ok ");
            p1=new JPanel();
            p1.add(b1);
            p2=new JPanel();
            p2.setLayout(new GridLayout(2,2));
            l1=new JLabel("Name :");
            l2=new JLabel("Password:");
            tf1=new JTextField(15);
            tf2=new JPasswordField(15);
            p2.add(l1);
            p2.add(tf1);
            p2.add(l2);
            p2.add(tf2);
            Container con=getContentPane();
            con.add(p1, BorderLayout.NORTH);
            con.add(p2, BorderLayout.CENTER);
            pack();
            setVisible(true);
        public static void createAndShowGUI()
            ex2.setDefaultLookAndFeelDecorated(true);
        public static void main(String ar[])
            createAndShowGUI();
            new ex2();
    }

  • Vector, what is the problem with this code?

    Vector, what is the problem with this code?
    63  private java.util.Vector data=new Vector();
    64  Vector aaaaa=new Vector();
    65   data.addElement(aaaaa);
    74  aaaaa.addElement(new String("Mary"));on compiling this code, the error is
    TableDemo.java:65: <identifier> expected
                    data.addElement(aaaaa);
                                   ^
    TableDemo.java:74: <identifier> expected
                    aaaaa.addElement(new String("Mary"));
                                    ^
    TableDemo.java:65: package data does not exist
                    data.addElement(aaaaa);
                        ^
    TableDemo.java:74: package aaaaa does not exist
                    aaaaa.addElement(new String("Mary"));Friends i really got fed up with this code for more than half an hour.could anybody spot the problem?

    I can see many:
    1. i assume your code snip is inside a method. a local variable can not be declare private.
    2. if you didn't import java.util.* on top then you need to prefix package on All occurance of Vector.
    3. String in java are constant and has literal syntax. "Mary" is sufficient in most of the time, unless you purposly want to call new String("Mary") on purpose. Read java.lang.String javadoc.
    Here is a sample that would compile...:
    public class QuickMain {
         public static void main(String[] args) {
              java.util.Vector data=new java.util.Vector();
              java.util.Vector aaaaa=new java.util.Vector();
              data.addElement(aaaaa);
              aaaaa.addElement(new String("Mary"));
    }

  • Cannot open Word File because "there are problems with the contents"

    Hi Everyone,
    I cannot open Word File because "there are problems with the contents" unspecified error; Location: 2.  Please help as I need this doc for work meeting this morning.  Nothing special about this doc but links were copied into it???  However I do that all the time.  I have never had this happen before.  I am on a 2010 machine.  I just ran a disk permissions repaired and emptied the trash but still no dice.  I had several other word docs up as well when I got up this morning but they are all fine.  I do not have Time Capsule turned on (which I need to do but that will be another thread/question).
    Thank you,
    sb

    Ok, I found a way to open this but not sure what happened to begin with and the formatting setup is different now, almost like text editor?  Not sure what happened here but hope it doesn't happen again?

  • Problems with sources of supply determination for external requirements.

    Hi gurus...
    My scenario is  SRM Classic Extended.
    We have a problems with sources of supply determination for external
    requirements comes from ECC. The shopping cart is created with successful
    based in the purchase requisition at ECC, but when i try to make the
    determination of sources of supply the system doesnt find any source of
    supply.
    There are a lot sources of supply creates for these parameters. The
    contracts were already replicated to ECC.
    This problem only occurs with external requirements comes from ECC, if i
    created a shopping cart directly at SRM, using the same parameters, the
    system propose the sources of supply correctly.
    Is there something that we can do?? This is the normal comportment for the souces of supply?
    Tks,
    Gustavo Nogueira

    Hello Gustavo Nogueira
    Then it is an issue.
    How are you searching the source of supply in sourcing cockpit.
    Can you replicate the issue?
    Let me know step by step,
    as per standard SAP , source of supply data must be available for shopping carts so that buyer can assign the source of supply.
    please share what source of supply you have there .

  • Problem with character code NCR (example : cộng h�a x� hội)

    Dear
    I have problem with character code NCR when display this string "c&#7897;ng h�a x� h&#7897;i" on web page using JSF. I print out like this c & # 7897 ; ng h � a x � h & # 7897 ; i
    Thanks for help

    jverd wrote:
    A better approach would be to take a char rather than a String in that method, since it's a better model for what you're converting. A char would also let you use switch statement.I was going to say this as well but you beat me to it.
    @OP, you really should use char for this. You're unnecessarily taking each char, converting it to a string, and working with the single-character string. That's not very efficient.

  • Problem with file transfer via Bluetooth

    I have been trying to receive some large files (43Mb) via bluetooth from another device but always get transfer fail message. But i could receive smaller flies...
    -Does this have anything to do with the device memory limit of 15MB?
    -How can i receive larger video files from other devices using bluetooth?
    -Does the BOLD have the same problem?
    Please help.
    Thanks

    What type of errors is being generated? Are you trying to save that file on device memory or media card? try moving that file on media card.
    tanzim                                                                                  
    If your query is resolved then please click on “Accept as Solution”
    Click on the LIKE on the bottom right if the post deserves credit

  • Problem with file transfer via wi-fi!

    Hi, folks,
    Please, could someone help me to get a music file I made using Groovemaker app?
    After finish the mix, I built a song. Then, I saved it in the "mix browser".
    In the end of the exporting process, I typed the URL address displayed in the browser (http://192.168.0.188:5555/, on Firefox, Chrome and IE), but something gone wrong and, every time I export the same song - it's my first exporting action - I got a message such "The page hasn't loaded... limit time reached".
    What's the problem with my wi-fi connection? Should I set something in my router? According to the company website (http://www.groovemaker.com/gmiphone/features/) this kind of wi-fi file transfer is easy, but not to me...
    Thanks in advance!
    Alex

    What type of errors is being generated? Are you trying to save that file on device memory or media card? try moving that file on media card.
    tanzim                                                                                  
    If your query is resolved then please click on “Accept as Solution”
    Click on the LIKE on the bottom right if the post deserves credit

  • LoadExternalModule throws error (-7 Unknown file extension) when working with source-code.

    Utility library function LoadExternalModule (admittedly marked as obsolete - but key to one of our older software)
    fails with error code (-7 Unknown file extension.)  in CVI 2012SP1 and 2013 Version 13.0.0(647) on Win7
    The suggested alternative Win32 API GetProcAddress doesn't work with source or obj files (so isn't an alternative at all)
    The Target-Settings to "Enable LoadExternalModule" are already checked.
    Any suggestions ?
    This code-snipped shows the behavior :
    // File "Main.c"
    #include <utility.h>
    int main(void)
    void (*funcPtr) (void);
    int moduleID;
    int status;
    // Library-Function-Error : -7 Unknown file extension.
    moduleID = LoadExternalModule ("Test.c");
    funcPtr = GetExternalModuleAddr (moduleID, "test_function", &status);
    (*funcPtr) ();
    return 0;
    // File "Test.c"
    void test_function(void)

    Hi,
    Thanks for teh inf regarding the LoadExternal Module,
    Using the LoadExternalmodule as you mentionned requires using a .obj file but this lead me to an issue getting a Control value from an .obj file called from a dll
    When using the LoadExternalModule function in CVI 2013, we can no longer use a .c file. Instead we have to use an .obj file.
    My issue is that' impossible for me to get a control value from an .iur managed by the .obj witchi is called by a dll. 
    Otherwise it's impossible for me to get the control vale when calling the .obj from a dll.
    Any suggestions Amigos
    Thanks

  • Socket problem with reading/writing - server app does not respond.

    Hello everyone,
    I'm having a strange problem with my application. In short: the goal of the program is to communicate between client and server (which includes exchange of messages and a binary file). The problem is, when I'm beginning to write to a stream on client side, server acts, like it's not listening. I'd appreciate your help and advice. Here I'm including the source:
    The server:
    import java.io.IOException;
    import java.net.ServerSocket;
    public class Server
        public static void main(String[] args)
            ServerSocket serwer;
            try
                serwer = new ServerSocket(4443);
                System.out.println("Server is running.");
                while(true)
                    ClientThread klient = new ClientThread(serwer.accept());
                    System.out.println("Received client request.");
                    Thread t = new Thread(klient);
                    t.start();
            catch(IOException e)
                System.out.print("An I/O exception occured: ");
                e.printStackTrace();
    }ClientThread:
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.net.Socket;
    import java.net.SocketException;
    public class ClientThread implements Runnable
        private Socket socket;
        private BufferedInputStream streamIn;
        private BufferedOutputStream streamOut;
        private StringBuffer filePath;
        ClientThread(Socket socket)
                this.socket = socket;     
        public void run()
            try
                 this.streamIn = new BufferedInputStream(socket.getInputStream());
                 this.streamOut = new BufferedOutputStream(socket.getOutputStream());
                int input;
                filePath = new StringBuffer();
                System.out.println("I'm reading...");
                while((input = streamIn.read()) != -1)
                     System.out.println((char)input);
                     filePath.append((char)input);
                this.streamOut.write("Given timestamp".toString().getBytes());
                ByteArrayOutputStream bufferingArray = new ByteArrayOutputStream();
                  while((input = streamIn.read()) != -1)
                       bufferingArray.write(input);
                  bufferingArray.close();
                OutputStream outputFileStream1 = new FileOutputStream("file_copy2.wav");
                  outputFileStream1.write(bufferingArray.toByteArray(), 0, bufferingArray.toByteArray().length);
                  outputFileStream1.close();
                this.CloseStream();
            catch (SocketException e)
                System.out.println("Client is disconnected.");
            catch (IOException e)
                System.out.print("An I/O exception occured:");
                e.printStackTrace();
        public void CloseStream()
            try
                this.streamOut.close();
                this.streamIn.close();
                this.socket.close();
            catch (IOException e)
                System.out.print("An I/O exception occured:");
                e.printStackTrace();
    }The client:
    import java.io.*;
    public class Client
         public static void main(String[] args) throws IOException
              int size;
              int input;
              //File, that I'm going to send
              StringBuffer filePath = new StringBuffer("C:\\WINDOWS\\Media\\chord.wav");
              StringBuffer fileName;
              InputStream fileStream = new FileInputStream(filePath.toString());
            Connect connection = new Connect("127.0.0.1", 4443);
            String response = new String();
            System.out.println("Client is running.");
              size = fileStream.available();
              System.out.println("Size of the file: " + size);
            fileName = new StringBuffer(filePath.substring(filePath.lastIndexOf("\\") + 1));
            System.out.println("Name of the file: " + fileName);
            connection.SendMessage(fileName.toString());
            response = connection.ReceiveMessage();
            System.out.println("Server responded -> " + response);
            ByteArrayOutputStream bufferingArray = new ByteArrayOutputStream();
              while((input = fileStream.read()) != -1)
                   bufferingArray.write(input);
              bufferingArray.close();
            FileOutputStream outputFileStream1 = new FileOutputStream("file_copy1.wav");
              outputFileStream1.write(bufferingArray.toByteArray(), 0, bufferingArray.toByteArray().length);
              outputFileStream1.close();
              byte[] array = bufferingArray.toByteArray();
              for (int i = 0; i < array.length; ++i)
                   connection.streamOut.write(array);
              response = connection.ReceiveMessage();
    System.out.println("Server responded -> " + response);
    connection.CloseStream();
    Connect class:import java.io.*;
    import java.net.Socket;
    import java.net.UnknownHostException;
    public class Connect
    public Socket socket;
    public BufferedInputStream streamIn;
    public BufferedOutputStream streamOut;
    Connect(String host, Integer port)
    try
    this.socket = new Socket(host, port);
    this.streamIn = new BufferedInputStream(this.socket.getInputStream());
    this.streamOut = new BufferedOutputStream(this.socket.getOutputStream());
    catch (UnknownHostException e)
    System.err.print("The Host you have specified is not valid.");
    e.getStackTrace();
    System.exit(1);
    catch (IOException e)
    System.err.print("An I/O exception occured.");
    e.getStackTrace();
    System.exit(1);
    public void SendMessage(String text) throws IOException
    this.streamOut.write(text.getBytes());
    System.out.println("Message send.");
    public void SendBytes(byte[] array) throws IOException
         this.streamOut.write(array, 0, array.length);
    public String ReceiveMessage() throws IOException
         StringBuffer elo = new StringBuffer();
         int input;
         while((input = streamIn.read()) != -1)
              elo.append((char)input);
         return elo.toString();
    public void CloseStream()
    try
    this.streamOut.close();
    this.streamIn.close();
    this.socket.close();
    catch (IOException e)
    System.err.print("An I/O exception occured: ");
    e.printStackTrace();

    The problem that was solved here was a different problem actually, concerning different source code, in which the solution I offered above doesn't arise. The solution I offered here applied to the source code you posted here.

Maybe you are looking for

  • Time machine back up of shared hard drive that is connected to AE

    I have 1TB MyBook external drive that I want to use as storage connected to my Airport Extreme. Naturally, this allows anyone connected to the wifi to access the files on there. I also have a second drive connected to the Airport Extreme. That one is

  • Brightness shortcut keys not working in Windows 8 or 8.1

    I'm no longer able to use the brightness shortcut keys after I've installed the Lenovo power management tool in Windows 8 on a Ideapad U300s. When the Lenovo power management tool is NOT installed on the system, pressing the shortcut keys brings up t

  • "You are not connected to the internet"  with a green light on Airport

    Using airport extreme with my MacBook, The airport shows a steady green light, but I cannot connect to the internet and my Safari shows "You are not connected to the internet". I tried getting a direct connection, but didn't work, I will be taking my

  • Reload page without posting

     

  • Change domain in number range

    Hi, Do you know how to change the "number length domain" of a "number range object"? We have a number range object using the domain "char7", it means 7 digits width, and we need to extend to 9 digits. The field "number length domain" is now disabled