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 8852283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:21:37+00:00 2026-06-14T13:21:37+00:00

Thanks for your time ,when my app run at line mycode = UTF-8 and

  • 0

Thanks for your time ,when my app run at line mycode = "UTF-8"and it jump directly to the catch.It’s very strange because I only set values to the string mycode.furthermore when I read txt files that are coded by ANSI,values of head[0],head[1] and head[2]are not -17``-69and-65,so the condition supposed to be dissatisfy.but the fact is app still execute the sentencemycode = "UTF-8".I can’t figure out the reason ,any help will be appreciate.

my code is below:

package com.example.tyghgy;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import android.util.Log;

public class MyTxt {

    private BufferedReader br = null;
    InputStream in = null;

    public MyTxt(){
          File f=null;
          f= new File("/sdcard/s.txt");
          String sssss;

          try {
           in = new BufferedInputStream(new FileInputStream(f));
           sssss = get_code();
          } catch (FileNotFoundException e3) {
           // TODO Auto-generated catch block
           e3.printStackTrace();
          }

          try {
           br = new BufferedReader(new InputStreamReader(in, "utf-8"));
          } catch (UnsupportedEncodingException e1) {
           // TODO Auto-generated catch block
           e1.printStackTrace();
          }


    }


    private String get_code(){
        String mycode = "";  
        byte[] head = new byte[3];  
        try{
        in.read(head);  

        if (head[0] == -1 && head[1] == -2 )  
            mycode = "UTF-16";  
        if (head[0] == -2 && head[1] == -1 )  
            mycode = "Unicode";  
        if(head[0]==-17 && head[1]==-69 && head[2] ==-65)  
            mycode = "UTF-8";  

        return mycode;
        }catch (Exception e) {
            // TODO: handle exception
            Log.v("sssssssssss", e.getMessage());
            mycode = e.getMessage();
            return mycode;
        }
    }
}
  • 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-06-14T13:21:38+00:00Added an answer on June 14, 2026 at 1:21 pm

    Use Environment.getExternalStorageDirectory().getAbsolutePath() for getting path of SDCARD as:

    String sdcardpath = Environment.getExternalStorageDirectory().getAbsolutePath();
    String fName = "s.txt";
    File f = new File(sdcardpath + File.separator + fName);
    //Your Code...
    

    And also make sure you have added following permission in manifest:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi everybody and thanks for your time, I read filenames in a QList. This
first of all thanks for taking your time! I'm a junior Dev, working with
Thanks For your Valuable support, Now i m able to run shell script in
First of all thank you for your time and sorry if some issues are
thanks for your reading. I am trying to modify Jquery Nivo Zoom plugin to
Thanks for your help! I'd like to output all companyName entries that have uploads
Thanks for your replies. First I am explaining my requirement :- I created my
Thanks for your answers to my previous question about GUI in java . I
Hi and thanks for your attention. First some background on the question: I have
In paypal, is it possible to skip the Thanks for your order page and

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.