Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 476461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:29:31+00:00 2026-05-13T00:29:31+00:00

This part of my code was creating xls file successfuly FileOutputStream fileOut = new

  • 0

This part of my code was creating xls file successfuly

FileOutputStream fileOut = new FileOutputStream("c:\\Decrypted.xls");
wb.write(fileOut);
fileOut.close();

when other part of the code had this statement ( which was before the above code )

in = new ByteArrayInputStream(theCell_00.getBytes(""));

But when I changed it to

in = new ByteArrayInputStream(theCell_00.getBytes("UTF-8"));

this part

FileOutputStream fileOut = new FileOutputStream("c:\\Decrypted.xls");
wb.write(fileOut);
fileOut.close();

is not generating any xls file anymore.

I need to change the encoding to UTF-8 as I have done in ByteArrayInputStream line, so what should I do that the code still generates xls file.

In case you need it, the two parts are taken from this function.

public void getExcel() throws Exception {

    try {
        ByteArrayInputStream in = null;
        FileOutputStream out = null;

        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet("new sheet");

        /*
         * KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128); SecretKey key =
         * kgen.generateKey(); byte[] encoded = key.getEncoded();
         * 
         * IOUtils.write(encoded, new FileOutputStream(new
         * File("C:\\Users\\abc\\Desktop\\key.txt")));
         */

        FileInputStream fin = new FileInputStream("C:\\key.txt");
        DataInputStream din = new DataInputStream(fin);

        byte b[] = new byte[16];

        din.read(b);

        InputStream excelResource = new FileInputStream(path);
        Workbook rwb = Workbook.getWorkbook(excelResource);
        int sheetCount = rwb.getNumberOfSheets();
        Sheet rs = rwb.getSheet(0);
        int rows = rs.getRows();
        int cols = rs.getColumns();
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < Col.length; j++) {
                String theCell_00 = rs.getCell(j, i).getContents();
                System.out.println("the Cell Content : " + theCell_00);

                in = new ByteArrayInputStream(theCell_00.getBytes(""));
                out = new FileOutputStream("c:\\Decrypted.txt");

                try {

                    // System.out.println(b);
                    SecretKey key1 = new SecretKeySpec(b, "AES");
                    // Create encrypter/decrypter class
                    AESDecrypter encrypter = new AESDecrypter(key1);

                    encrypter.encrypt(new ByteArrayInputStream(theCell_00.getBytes()),
                        new FileOutputStream("temp.txt"));
                    // Decrypt
                    // encrypter.encrypt(,new FileOutputStream("Encrypted.txt"));

                    encrypter.decrypt(in, out);

                    try {
                        if (out != null)
                            out.close();
                    } finally {
                        if (in != null)
                            in.close();
                    }

                    // encrypter.decrypt(new
                    // ByteArrayInputStream(theCell_00.getBytes(Latin_1)),new
                    // FileOutputStream("c:\\Decrypted.txt"));
                    String filename = "c:\\Decrypted.txt";

                    BufferedReader bufferedReader = null;

                    try {

                        // Construct the BufferedReader object
                        bufferedReader = new BufferedReader(new FileReader(filename));
                        // System.out.println(bufferedReader.readLine());
                        String line = null;

                        while ((line = bufferedReader.readLine()) != null) {
                            // Process the data, here we just print it out

                            /*
                             * HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet =
                             * wb.createSheet("new sheet"); HSSFRow row = sheet.createRow(2);
                             */
                            // System.out.println(i);

                            HSSFRow row = sheet.createRow(i);
                            int s_col = 0;
                            row.createCell(s_col).setCellValue(line);
                            // s_col++;
                            // row.createCell(1).setCellValue(new Date());
                            FileOutputStream fileOut = new FileOutputStream("c:\\Decrypted.xls");
                            wb.write(fileOut);
                            fileOut.close();

                            // System.out.println(line);
                        }

                    } catch (FileNotFoundException ex) {
                        ex.printStackTrace();
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    } finally {
                        // Close the BufferedReader
                        try {
                            if (bufferedReader != null)
                                bufferedReader.close();
                        } catch (IOException ex) {
                            ex.printStackTrace();
                        }
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }
        rwb.close();
    } catch (Exception ex) {
        ex.printStackTrace();
        ex.getMessage();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:29:31+00:00Added an answer on May 13, 2026 at 12:29 am

    What data types are expected by the call to AESDecrypter.decrypt? Does it have to take in a FileOutputStream object? Or can you pass in a Writer or other OutputStream?

    I normally do something like this to write UTF-8 output:

    Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("c:\\Decrypted.txt"), "UTF-8"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this part of code in my functions.php: function cc_admin_enqueue_scripts($hook) { $file_dir=get_bloginfo('template_directory'); wp_enqueue_script('media-upload');
I am trying to learn and writting this part of code. while testing few
I'm studying data structures (List, Stack, Queue), and this part of code is confusing
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
This part of my code is used to award a grade to a student
It seems that this part of my code is where the exception occurs: c
I just started learning C but I don't understand this part of the code.
this is part of my code which reads an http response. It's supposed to
The code we're using is straightforward in this part of the search query: myCriteria.Add(
Im geting exception whene the code comes to this part : [GridAction] public JsonResult

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.