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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:29:42+00:00 2026-06-11T10:29:42+00:00

Here is my source code. I got the reading part but need a simple

  • 0

Here is my source code. I got the reading part but need a simple logic for my writing part which I”m not getting. Here in my current logic, data gets overwritten and I’m always able to see the last block of read data in my written file.

import java.io.File;
import java.io.FileInputStream;
java.io.FileNotFoundException;
java.io.FileOutputStream;
import java.io.IOException;
public class LoadTest 
 {  
public void readFiles(File file) throws FileNotFoundException
       {
        int fsize = (int) file.length();
        int part = (fsize/4)+(fsize%4);
        byte[] block = new byte[part]; 
        FileInputStream fin = new FileInputStream(file);
        try
        {
            int val=-1;
            do
            {
                int bytesread =0;
                while(bytesread<part)
                    {
                        val = fin.read(block, bytesread, part-bytesread);
                        if (val<0)
                            break;
                        bytesread += val;

                    }
                writeFiles(block,bytesread);                            
            }
            while(val>=0);
            fin.close();
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }

    }
public void writeFiles(byte[] block, int len) throws IOException
{
    int byteswritten = 0;
    FileOutputStream fout = new FileOutputStream("input.csv");
    fout.write(block, byteswritten, len+byteswritten);
    byteswritten +=len;
    fout.close();
}


public static void main(String[] args) throws FileNotFoundException
{  
    LoadTest testobj = new LoadTest();
    String folder = "/Users/NiranjanSubramanian/Desktop/TestFiles";
    File dir = new File(folder);
    File[] files = dir.listFiles();
    System.out.println("Started");
    for( File entry: files)
    {  
        testobj.readFiles(entry);

    }
    System.out.println("Ended");

}

}

  • 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-11T10:29:43+00:00Added an answer on June 11, 2026 at 10:29 am

    See my comments for how to solve the issue in a simple manner. However, let me suggest to you a simple alternative to do what you’re asking.

    final Path dir = Paths.get("/Users/NiranjanSubramanian/Desktop/TestFiles");
    try (final OutputStream out = Files.newOutputStream(Paths.get("input.csv"))) {
      for (final Path file : Files.newDirectoryStream(dir)) {
        Files.copy(file, out);
      }
    }
    

    This relies on Java 7’s new file API but is (at least in my opinion) a far cleaner solution.

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

Sidebar

Related Questions

(NOTE: Source code here https://github.com/cthielen/dss-evote ) I've got a simple voting application. A survey
I have an application I need to analyze. I have the source code here.
I saw some code when studying the open source project: here . But I
Update : Reading directly the django source code i got one undocumented missing piece
I got the source code from here http://weblogs.asp.net/scottgu/archive/2006/04/13/442772.aspx is it compatible with latest ASP.net
Here is source code: @OneToOne(fetch = FetchType.LAZY) @Cascade({SAVE_UPDATE, EVICT, DELETE}) @JoinColumn(name = A_ID, nullable
you can view full source code here dpaste.com/hold/167199 Error: delete() takes exactly 2 arguments
I am trying to install MySQLdb package. I found the source code here .
Here's the relevant bit of the source code: class Dice { String name ;
I download the latest source code from here: http://aspnetwebstack.codeplex.com/SourceControl/list/changesets 1) add the system.web.mvc project

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.