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

  • Home
  • SEARCH
  • 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 8862453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:43:58+00:00 2026-06-14T15:43:58+00:00

Sample code is :- import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.File; import java.io.FileNotFoundException;

  • 0

Sample code is :-

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;

public class CopyBytes {

    public static void main(String [] args){
    CopyBytes obj = new CopyBytes();
    File file = new File("/home/mount/Data/JAVA/xanadu.bak");
    obj.copyBytes(file);
    }

    public void copyBytes(File ifile){
    FileInputStream reader = null;
    FileOutputStream output =null;
    int c=0;
    try{
    reader = new FileInputStream(ifile);
    output = new FileOutputStream("outfile");
    while((c = reader.read()) != -1)
    {
        System.out.print(c);
        output.write(c);
    }   
        System.out.println();
    }
    catch(FileNotFoundException fnfex){
    fnfex.getMessage();
    fnfex.printStackTrace();
    }
    catch(IOException ioex){
    ioex.getMessage();
    ioex.printStackTrace();
    }
    finally{
    if(reader !=null)
    {
        System.out.println("Closing the Stream");
        try{
        reader.close();
        System.out.println("Closed the Streams");
        }
        catch(IOException ioex)
        {
            ioex.printStackTrace();
        }
    }
    else{
    System.out.println("Stream not open");
    }
}
}
}

Contents of the xanadu.bak are as follows:-

buffer@ankit:/home/mount/Data/JAVA/practice/src/fileio.bytestreams.com$ cat /home/mount/Data/JAVA/xanadu.bak
IA

When above code is run;it gives following output:

buffer@ankit:/home/mount/Data/JAVA/practice/src/fileio.bytestreams.com$ java CopyBytes

736510
Closing the Stream
Closed the Streams

whereas i should get

7365
Closing the Stream
Closed the Streams

The file to which I am writing is perfectly fine. Please provide your valuable inputs.

  • 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-14T15:43:59+00:00Added an answer on June 14, 2026 at 3:43 pm

    The last character printed is 10d, or 0x0A. That’s a newline character. Other combinations like 0x0D 0x0A or the reverse could happen on other platforms.

    A lot of editors add a newline at the end of files if there isn’t one, and that’s what you’re seeing.

    Use something like hexdump to ascertain what your file really contains.
    You code works pretty well for that too 🙂

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

Sidebar

Related Questions

My code sample: import java.math.*; public class x { public static void main(String[] args)
Sample Code is :- import java.io.*; public class WriteInt{ public static void main(String []
Here is a sample code package org.example; import java.lang.reflect.Method; class TestRef { public void
The sample code is:- import javax.sound.midi.*; import java.io.*; class test{ public void go() throws
my code: package sample; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import com.hp.hpl.jena.query.Query;
I have a sample code : import java.awt.*; import javax.swing.*; import javax.swing.border.BevelBorder; public class
I have following code: import java.io.*; import java.util.concurrent.* ; public class Example{ public static
import java.util.Collection; public class Test { public static void main(String[] args) { Collection c
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
Here is a simple piece of code: import java.io.*; public class Read { public

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.