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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:35:53+00:00 2026-05-24T23:35:53+00:00

I am using this code to read a txt file, line by line. //

  • 0

I am using this code to read a txt file, line by line.

// Open the file that is the first command line parameter 
FileInputStream fstream = new FileInputStream("/Users/dimitramicha/Desktop/SweetHome3D1.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
// Read File Line By Line
int i = 0;
while ((strLine = br.readLine()) != null) {
    str[i] = strLine;
    i++;
}
// Close the input stream
in.close();

and I save it in an array.

Afterwards, I would like to make an if statement about the Strings that I saved in the array. But when I do that it doesn’t work, because (as I’ve thought) it saves also the spaces (backslashes). Do you have any idea how I can save the data in the array but without spaces?

  • 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-24T23:35:54+00:00Added an answer on May 24, 2026 at 11:35 pm

    I would do:

    strLineWithoutSpaces = strLine.replace(' ', '');
    str[i] = strLineWithoutSpaces;
    

    You can also do more replaces if you find other characters that you don’t want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using this code import re file = open('FilePath/OUTPUT.01') lines = file.read() file.close() for match
As of now, I am using this code to open a file and read
I am currently using a code construction like this: string line; using (System.IO.StreamReader file
I have used this code var dest1 = File.AppendText(Path.Combine(_logFolderPath, log1.txt)); dest1.WriteLine(line.Trim()); to write to
I am trying to read a file located at C:\Users\Siddharth\Documents\aarti\yeh_vidhi_mangal.txt. Following code indicates that
I'm using this code, and I get the stack trace that is listed below.
I am using this code to read values from an isolated storage IsolatedStorageFile isoStore
So I have the following code where I should read a Text File (This
I'm trying to read a text file line by line using InputStream from the
I'm writing to a text file using the code below. the setup is: read

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.