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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:16:36+00:00 2026-06-04T12:16:36+00:00

I have a method that reads a random joke from a file in raw,

  • 0

I have a method that reads a random joke from a file in raw, and then displays it, but i can’t figure out, how to set a new line.
All the jokes in the line are 1 line, but obviously they are more than one so i use \n. For instance the line says "Hi! \n Hi to you too" When i use my code instead of:

Hi!
Hi to you too

it gives me

Hi! \n Hi to you too

I tried to append it, and that didn’t work with the code bellow also tried to enter the joke in array and then display it from that array, did’t work either… Any ideas would be much appreciated…

InputStreamReader inputStream = new InputStreamReader
         (getResources().openRawResource(R.raw.vicove));
         BufferedReader br = new BufferedReader(inputStream);
         int numLines = 1;
         Random r = new Random();
         int desiredLine = r.nextInt(numLines);

         String theLine="";
         int lineCtr = 0;
        try {
    while ((theLine = br.readLine()) != null)   {
    if (lineCtr == desiredLine) {
    break;
    }
        lineCtr++;
        }
        } catch (IOException e) {

            e.printStackTrace();
            }

     textGenerateNumber.setText(String.valueOf(theLine));

I’ve used the same code to read files with no escape characters and it works perfectly…
P.S. Not only \n wouldn’t work, but also \" and probably any other.

  • 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-04T12:16:38+00:00Added an answer on June 4, 2026 at 12:16 pm

    try this:

    String source = "<br>"+String.valueOf(theLine);  
    textGenerateNumber.append(Html.fromHtml(source));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that reads data from a comma separated text file and
I have a method that reads a file. This file has roughly 30000 lines.
I have a webservice method that reads a photo and returns its byte data.
I have one method that opens a file and passes off to another function
First, I have a class that extends AsyncTask. Then in the doInBackground() method, I
I have a Runnable that gets a line to the Mic, reads from it
I have a service application that on startup reads an XML file and starts
If I have a multi-threaded program that reads a cache-type memory by reference. Can
I have a C# database layer that with static read method that is called
I have a method that accepts an IEnumerable-decimals and performance various math functions. I

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.