Home Answers Viewqa Java-Beginners Reading and writting multiple files

 
 


alain ndayishimiye
Reading and writting multiple files
2 Answer(s)      a year and 4 months ago
Posted in : Java Beginners

how can i read and write say two different files at the same time using threads.

View Answers

January 19, 2012 at 5:41 PM


import java.io.*;
class ReadFileUsingThread
{
    public void readFromFile(final String f, Thread thread) {
    Runnable readRun = new Runnable() {
      public void run() {
        BufferedWriter pw=null;
        FileInputStream in=null;
        String text = null;
        try{
            pw = new BufferedWriter(new FileWriter("C:/New/"+new File(f).getName()));
          Thread.sleep(5000);
          File inputFile = new File(f);
          in = new FileInputStream(inputFile);
          byte bt[] =  new byte[(int)inputFile.length()];
          in.read(bt);
          text = new String(bt);
          pw.write(text);
          pw.newLine();
          pw.close();
       } catch(Exception ex) {
       }  
      }
    };
    thread = new Thread(readRun);
    thread.start();
  }

    public static void main(String[] args) 
    {
        ReadFileUsingThread f=new ReadFileUsingThread();

        File file = new File("C:/Files/");
         FilenameFilter filter = new FileFilter();
        File[] files = file.listFiles(filter);
        Thread thread[]=new Thread[files.length];
        for(int i = 0; i < files.length; i++) {
           thread[i]=new Thread();
        f.readFromFile(files[i].getPath(),thread[i]);
        }
    }
}
class FileFilter implements FilenameFilter {
        public boolean accept(File dir, String name) {
                return name.endsWith("txt");
        }
 }

January 20, 2012 at 12:33 PM


i did you example but it crashes with big file how come. i get this error

:Thread-1" java.lang.OutOfMemoryError: Java heap space









Related Pages:
Reading and writting multiple files
Reading and writting multiple files  how can i read and write say two different files at the same time using threads
reading multiple files from a directory and writing them into a single file
reading multiple files from a directory and writing them into a single file... this: /*this program reads multiple files * from a single directory. */ package elite.tech.com... File(inpath); File files[]; files = Folder.listFiles
Uploading Multiple Files Using Jsp
Uploading Multiple Files Using Jsp  ... to understand how you can upload multiple files by using the Jsp. We should avoid... a file. In this example we are going to tell you how we can upload multiple files
Reading files in Java
Reading files in Java  I have to make a program in my project.... Please provide me the example code for reading big text file in Java. What do you suggest for Reading files in Java? Thanks
Reading and Writing files - Java Beginners
Reading and Writing files  Hello, please help me to Develop a simple Java application that, when run, Welcomes the users and tells them the name... to investigate writing to files a little (can be also done using Properties
Reading Text file and storing in map
Reading Text file and storing in map  Hi I have multiple text files. I want to read thoses files and store those records in map. Map will be of "LinkedHashMap<String, Map<String, String>>" type. Please let me know
Reading Files and Print - Java Beginners
Reading Files and Print  Hey Guys, I'm a beginner to java and I wanna write this program. I wanna create files including information.... There are almost 30 files. When I want to find students whose school is "School
Renaming multiple files
Renaming multiple files  Hi, I have number of files in a directory. Files are named as: 1DeoyaRohit0705$.mp4,2DeoyaRohit0705$.mp4, 3_DeoyaRohit0705$.mp4. .... Now I wanted to rename these files as: 1RohitBBorse.mp4
Upload and Download multiple files
Upload and Download multiple files  Hello Sir/Madam, I need a simple code for upload and download multiple files(it may be image,doc and txt)which has to be store in database and also retrieve the file from database
Dynamic include of multiple files
Dynamic include of multiple files  I want to include a series of small files, based on a string. For instance, if the string was: String fileString="a b c d e"; I would split it into an array, fileArray, and do something like
Uploading Multiple Files Using Jsp
Uploading Multiple Files Using Jsp  ... to understand how you can upload multiple files by using the Jsp. We should avoid... a file. In this example we are going to tell you how we can upload multiple files
Merging multiple PDF files - Framework
Merging multiple PDF files  I m using the iText package to merge pdf files. Its working fine but on each corner of the merged filep there is some... the files are having different font.Please help
save output in multiple text files
save output in multiple text files  Hi..I'm getting problem to store the output of this php code into multiple text files. Can anyone sugeest. Here is my code: <?php for($i=1; $i<=100; $i++) { $html = file_get
Java read multiple files
Java read multiple files In this section you will learn how to read the data of multiple files. Here we have created four files that includes information.... We have to find the students according to particular school from all the files
Uploading the multiple files
. For uploading the multiple files at a time, first create a table as per required...; <HTML> <HEAD> <TITLE> Multiple Files Upload </TITLE>...="#FFFFFF"> <tr> <td><strong>Multiple Files
Copy multiple files
Copy multiple files        In this section, you will learn how the data of multiple files.... For copping the data of multiple file, you need all files in a specified directory where
retrieve multiple columns values from multiple csv files in java
retrieve multiple columns values from multiple csv files in java  Suppose there is folder in C:\fileupload which contains these two csv files... these two files and store in oracle database as: VendorID,Name,Address and plz
Source file upload by attaching multiple files
Source file upload by attaching multiple files  Hi, I am trying to develop a file upload with multiple files attached functionality in java(like in gmail or in picasa). The source I found so far will select a single file. When I
Source file upload by attaching multiple files
a provision to attach multiple images/files like in gmail. Is there any solution...Source file upload by attaching multiple files  Thanks for the answer. The answer posted in this link I want to have a single text box and when i
Uploading multiple files in JSP - JSP-Servlet
Uploading multiple files in JSP  Hi, I have this code in JSP for Uploading multiple files : Samples : Simple Upload... modification I need to do in the code to upload all the files attached. 
Reading from remote files using PHP,Ubuntu and Windows machine.
Reading from remote files using PHP,Ubuntu and Windows machine.  Hi, Great work you doing here and I totally love the look and feel of the new site... on a windows machine within the same network. After reading from it, the script
How to convert multiple files in java to .zip format
How to convert multiple files in java to .zip format  i receive multiple files from a remote URL as for (String reportid : reportList...://Answers//Examples"); File[] files = folder.listFiles(); File file=new File
help me plz:-Merge multiple jasper files into Single one
help me plz:-Merge multiple jasper files into Single one  how to Merge multiple jasper files into Single one word doc
find jar file name from multiple set of jar files
find jar file name from multiple set of jar files   I would like to find jar file name from multiple set of jar files where the given class nameââ?¬Â?com.rational.ft.util.debugââ?¬Â
how to upload multiple files in jsp and saving the path in database and the file in folder
how to upload multiple files in jsp and saving the path in database and the file in folder  how to upload multiple files in jsp and saving the path in database and the file in folder I have created a form for the upload of files
Writing and Reading A File
Writing and Reading A File  Hello, I've been trying to learn writing and reading data from file for our assignment, but just stuck on how to proceed...: http://www.roseindia.net/tutorial/java/core/files/insertfiledataToJTable.html
java program to read multiple files from a directory and display them on a jframe
java program to read multiple files from a directory and display them on a jframe  hi guys i want to write a java program that will read all files in a directory and display them one by on on a jframe on jpanel with specific key
document reading in java - Java Beginners
document reading in java  Hi Dipak, Can you tell me how to read pdf files in to java.i want convert pdf file in xml format through java coding.can you please help me?  Hi Friend, Try the following code
Mutliple files upload
Mutliple files upload  Hi Sir, Am doing a project in Jsp and Servlets, i want to upload multiple files inside the grid of the table, and submit the form.Send em the answers as soon as possible..   Please visit
Why we are writting public static void main(String args[])?
Why we are writting public static void main(String args[])?  Why we are writting public static void main(String args[])? please elaborate it... and also explain the statement System.out.println("abc
for writting java program why we are taking more than one class
for writting java program why we are taking more than one class  for writting java program only one class is enough but why we are taking more than one class
multiple language support iPhone
multiple language support iPhone  Is it possible to create an application in iPhone that can support multiple languages.   Yes, iPhone/iPad... the project location and create two project files for example en.lproj
Copy Files - Java Beginners
Copy Files  I saw the post on copying multiple files (http://www.roseindia.net/java/example/java/io/CopyMultipleFiles.shtml) and I have something... a list of JPEG files that my boss gave me, and I was planning on putting them
Multiple file upload - Struts
Multiple file upload  HI all, I m trying to upload multiple files using struts and jsp. I m using enctype="multipart". and the number of files... files uploaded Thanks  HI The code above will work
listing files - Java Beginners
]); System.exit(0); default : System.out.println("Multiple files...]); System.exit(0); default : System.out.println("Multiple files are not allow...listing files  how to list the files and number of files only
reading data from excel file and plotting graph
reading data from excel file and plotting graph  I am doing a project using NetBeans in which i have to take input an excel file and then using... thing I'll be highly thankful to you:) I want to draw multiple charts
Uploading Multiple Image On Server?
;Struts 2 upload multiple files example</h1> <s:form action="resultAction...Uploading Multiple Image On Server?  Hello sir, I am stuck with a problem of uploading multiple images on server. i have done a code which works
Error in reading Excel data using jsp
Error in reading Excel data using jsp  ERROR while executing bellow... and POI library files are there in respective folders. the printStackTrce... convert it and display as a spreadsheet. HSSF deals with files written in Excel
Directories and Files
Java NotesDirectories and Files Put all source files into a directory, one... for the source files. The directory name should be lowercase letters, with no blanks.... It's easy to do. Here are a couple of minor rules. Make sure all classes (.java files
files
/core/files/storeobjectsinFile.html
files
files  write a java program to calculate the time taken to read a given number of files. file names should be given at command line.   Hello Friend, Try the following code: import java.io.*; import java.util.*; class
retrieving image files - JSP-Servlet
retrieving image files  How to retrieve multiple images at a time from mysql database using JSP
Reply to the mail(import files error)
Reply to the mail(import files error)  Hi! Thank you. That error has... as org.hibernate.MappingException: Error reading resource: contact.hbm.xml...-to-the-mail(import-files-error).html Thanks
multiple file upload at a time like gmail
multiple file upload at a time like gmail  I want to upload multiple files at a time like gmail. is there any possiblity/solution to do that?   Hi Friend, Please visit the following link: Upload Multiple Files Thanks

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.