Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
How to pass the file path as an argument in RandomFileAccess Object in android?

There is a small problem in the following code that it is unable to find the text file src/main/res/raw/dictionary.txt:

 RandomAccessFile ifl = new RandomAccessFile("android.resource://" 
                               + getPackageName() + "/" + R.raw.dict , "r");

Is there any other way by which the text file can successfully be found and opened? Is there a way if we keep these files in 'assets' folder and then access? Plz suggest.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

you can better use InputStream to read text in raw folder file ,

 public String readRawFile()
{
     StringBuilder builder = new StringBuilder();
     InputStream in = getResources().openRawResource(R.raw.yourfile);
  try {
       int count = 0;
       byte[] bytes = new byte[32768];
       while ( (count = in.read(bytes,0, 32768)) > 0) {
           builder.append(new String(bytes, 0, count));
       }

       in.close();
   } catch (IOException e) {
       e.printStackTrace();
   }
   return builder.toString();
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!