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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:13:15+00:00 2026-05-27T12:13:15+00:00

In the FileHandle Class there is a fileHandleWithStandardOutput method. According to the Documentation ,

  • 0

In the FileHandle Class there is a fileHandleWithStandardOutput method. According to the Documentation, "Conventionally this is a terminal device that receives a stream of data from a program."

What I want to do is read a file per 128 bytes and display it to the terminal, using fileHandleWithStandardOutput method.

Here’s a code fragment of how am I reading it per 128 bytes.

i = 0;
while((i + kBufSize) <= sourceFileSize){
        [inFile seekToFileOffset: i];
        buffer = [inFile readDataOfLength: kBufSize];
        [outFile seekToEndOfFile];
        [outFile writeData: buffer];
        i += kBufSize + 1;        
    }

//Get the remaining bytes...
[inFile seekToFileOffset: i ];

buffer = [inFile readDataOfLength: ([[attr objectForKey: NSFileSize]intValue] - i)];
[outFile seekToEndOfFile];
[outFile writeData: buffer];

kBufSize is a preprocessor which is equal to 128;


My Answer:

Set outFile the return NSFileHandle of fileHandleWithStandardOutput..

I tried it before..but it didn’t worked..and now it worked. May be there is something else or something is interfering. Anyways I got the answer now.

  • 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-27T12:13:15+00:00Added an answer on May 27, 2026 at 12:13 pm

    You don’t need to seek each time you read from or write to the FileHandle. Your code could be simplified as follows:

    NSData *buffer;
    
    NSFileHandle *outFile = [NSFileHandle fileHandleWithStandardOutput];
    
    do {
        buffer = [inFile readDataOfLength: kBufSize];
        [outFile writeData:buffer];
    } while ([buffer length] > 0);
    

    I’m not sure why you’re reading in 128 byte chunks, but if that isn’t necessary then you could eliminate the loop and do something like this instead (assuming your input file is not so huge it exceeds the maximum for an NSData object):

    NSFileHandle *outFile = [NSFileHandle fileHandleWithStandardOutput];
    buffer = [inFile readDataToEndOfFile];
    [outFile writeData:buffer];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When reading from a IO::Socket::INET filehandle it can not be assumed that there will
I have an object with a method that returns a filehandle, and I want
I have a subroutine that takes a filehandle as an argument. How do I
I have a class that assists in importing a special type of file, and
Lets say, for example, that I have a class that requires the use of
I am new to creating plug-ins, and there's much that I don't understand. One
I want to write a file_handle class like this #include <stdio.h> #include <iostream> #include
I have a class generating error output that I'd like to output using Logger.
I have a filehandler class that moves an xdoument to cache using a lock.
I would like to create a class that describes a file resource and then

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.