1

I have an excel file: test_excel.xls

I want to read content inside.

What I do:

1) Upload file from client

2) Parse to Base64 String (using javascript)

3) From Base64 Convert to Byte

4) Upload Byte String to server

5) I stuck in here, I don't know how to get the data, I have tried many way (Apache POI, convert to FileInputStream..)

Do anybody have ideas on this problem ?

1
  • Why are you using the client to do the base 64 decoding? The server can do that. The client doesn't have to be involved AFAICS. Commented Sep 10, 2013 at 7:05

1 Answer 1

1

Upload the file, get byte[] out of it like this:

public static byte[] getByteStream(File file) {
    byte[] b = new byte[(int) file.length()];
    try {
        FileInputStream fileInputStream = new FileInputStream(file);
        fileInputStream.read(b);
        for (int i = 0; i < b.length; i++) {
            //System.out.print((char) b[i]);
        }
    } catch (FileNotFoundException e) {
        System.out.println("File Not Found.");
        e.printStackTrace();
    } catch (IOException e1) {
        System.out.println("Error Reading The File.");
        e1.printStackTrace();
    }
    return b;
}

And use it with Apache POI or any other 'excel' framework to read its values.

P.S. you might want to clean the code, I just grabbed the first thing I remembered and from what I can see it could use some cleaning smile

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.