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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:19:21+00:00 2026-06-06T04:19:21+00:00

How to use FileReader not to use BufferReader i want to use File,FileReader for

  • 0

How to use FileReader not to use BufferReader i want to use File,FileReader for this program of file reading from ftp

    public class FileReader {


public final static String SERVER = "ftp://server.com";
public final static String USER_NAME = "user";
public final static String PASSWORD = "password";
public final static String FILE_NAME = "Sorting Cloumns Dynamically - Java Scripts.txt";

public static void main(String[] args) {

    System.out.println("Connecting to FTP server...");

    // Connection String
    URL url;
    try {
        url = new URL("ftp://" + USER_NAME + ":" + PASSWORD + "@" + SERVER+ "/study/" + FILE_NAME +";type=i");


        URLConnection con = url.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));

        System.out.println("Reading file start.");

        String inputLine;
        while ((inputLine = in.readLine()) != null)
            System.out.println(inputLine);
        in.close();
        }
        catch (FileNotFoundException e) {
            System.out.println("File not find on server.");
            System.exit(0);
        }catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("Read File Complete.");

}

    }

this code for i have created

  • 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-06T04:19:23+00:00Added an answer on June 6, 2026 at 4:19 am

    You have to convert the input stream into a file and then use File Reader.

            URL url;
            try {
                url = new URL("ftp://" + USER_NAME + ":" + PASSWORD + "@" + SERVER
                        + "/study/" + FILE_NAME + ";type=i");
                URLConnection con = url.openConnection();
                File tmpFile = new File("tmpFile.java");
                OutputStream out = new FileOutputStream(f);
    
                InputStream inputStream = con.getInputStream();
    
                byte buf[] = new byte[1024];
                int len;
                while ((len = inputStream.read(buf)) > 0)
                    out.write(buf, 0, len);
                out.close();
                inputStream.close();
    
            } catch (IOException e) {
            }
    

    The obove code creats a file object tmpFile from the input stream. You can use Filereader on this file object.

      FileReader fileReader=new FileReader(tmpFile);
        int ch= fileReader.read();
        while(ch != -1){
        System.out.print((char)ch);
        ch = fileReader.read();
        }
        fileReader.close();
    

    Notice that File Reader reads character by character.Thats why people prefer BufferedReader over it.

    In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,

    BufferedReader in
       = new BufferedReader(new FileReader("foo.in"));
    

    will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.

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

Sidebar

Related Questions

use C#,want to upload excel file on google doc. bellow syntax use to upload
A file name will be passed in from standard in. I want to open
I am trying to use the 'FileReader' and 'File' APIs that are supported in
I'm reading numbers from a txt file using BufferedReader for analysis. The way I'm
I want to use File f = new File(C:\\); to make an ArrayList with
I'm trying to create a FileReader (not a Document ) from an XMLResponse like
So I have a FileReader class, it looks like this: #define DISALLOW_COPY(type) \ type(const
My code makes use of BufferedReader to read from a file [main.txt] and PrintWriter
This is a method I'm using to load saved game data from a file.
I'm trying to use the wordalignment in the BerkeleyAligner.jar file from http://code.google.com/p/berkeleyaligner/ in my

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.