hai everyone,
Can anybody please tell me how to copy the contents of one file into many files at a time simultaneously? I want a JAVA source code for it please help
Thank you
7 5368
Have you read the Basic I/O section of Sun's Tutorial?
If you are new to the concepts involved this is a good place to start. Also you may find it productive to put the "simultaneous" bit on hold until you are sure about writing the code needed for basic file copying.
-
-
import java.io.File;
-
import java.io.FileInputStream;
-
import java.io.FileOutputStream;
-
import java.io.IOException;
-
import java.io.InputStream;
-
-
public class JFileCopier {
-
-
private JFileCopier(){
-
}
-
-
private static final JFileCopier INSTANCE = new JFileCopier();
-
-
public static JFileCopier getInstance(){
-
return INSTANCE;
-
}
-
-
public static void main(String[] args) {
-
String[] targetFiles = { "C:\\target1.txt","C:\\target2.txt"};
-
try {
-
JFileCopier.getInstance().copyFileContentToTargetFilesSynch("C:\\source.txt", targetFiles);
-
} catch (IOException e) {
-
e.printStackTrace();
-
}
-
}
-
-
public void copyFileContentToTargetFilesSynch(String sourceFile , String[] targetFiles) throws IOException{
-
File sFile = new File(sourceFile);
-
InputStream sFileInputStream = new FileInputStream(sFile);
-
long length = sFile.length();
-
-
byte[] sFileBytes = new byte[(int) length];
-
int offset = 0,numRead = 0;
-
while (offset < sFileBytes.length
-
&& (numRead = sFileInputStream.read(sFileBytes, offset,
-
sFileBytes.length - offset)) >= 0) {
-
offset += numRead;
-
}
-
sFileInputStream.close();
-
-
-
for(String targetFile : targetFiles){
-
new CopierThread(sFileBytes,targetFile).run();
-
-
}
-
-
}
-
-
class CopierThread extends Thread {
-
byte[] content;
-
String targetFileName;
-
public CopierThread(byte[] content, String targetFileName) {
-
super();
-
this.content = content;
-
this.targetFileName = targetFileName;
-
}
-
public void run() {
-
try {
-
FileOutputStream out = new FileOutputStream(targetFileName,true);
-
out.write(content);
-
out.close();
-
} catch (IOException e) {
-
System.err.println(targetFileName + " error : " + e.getMessage());
-
}
-
}
-
}
-
-
}
-
-
Can you explain what do you mean by paragraph. from what type of file you are reading. from simple text file or doc file.
In general sense a paragraph is a sequence of character without a new line in between. say you have written a 10 line document in note pad without pressing a single enter the entire 10 line would be a paragraph. But if you open any documents, as example, of RFC you will figure out that each paragraph is separated with two new lines.
If a single new line define the new paragraph then read line is the simplest solution. But if there is different strategy to identify then you may have to work on it.
But if you are talking about other then pain text file then you may have to look in the reference of that specific file type references.
By the way there is 5 paragraph above this line according to my definition. there is no newline in any paragraph. But at least to newline after each paragraph :)
Regards,
Johny
so, I can guess is a single new line is not the paragraph. more than one new line is paragraph.
what you can do is read line by line. when you are getting a line=="" then you can count is one paragraph is received. as example This memo provides information for the Internet community. It does
not specify an Internet standard of any kind. Distribution of this
memo is unlimited.
This document describes the commonly used base 64, base 32, and base
16 encoding schemes. It also discusses the use of line-feeds in
encoded data, use of padding in encoded data, use of non-alphabet
characters in encoded data, and use of different encoding alphabets.
Look at the above text in bold(you dont have to read the text). there is two paragraph. how do we know that? simple few empty lines between paragraph. But in normal read line function you get 9 lines. so you can judge the paragraph by empty line between paragraph. so write your won program that will look for empty lines. if you get empty lines its a new paragraph. But I am not sure whether you will find a built in function to read paragraph or not. :)
Regards,
Johny
qlluq,
Usually we are not in the business of providing full source solutions. Since that doesn't help anyone learn their craft better.
"You can give a man a fish and he will eat for a day, or you can teach a man to fish and he will eat for a lifetime."
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tess |
last post by:
Hi,
Long time reader, first time poster... Any help is appreciated.
I have a few questions regarding Winform controls embedded within an
html page. For more info please see the appendix. Now,...
|
by: SOR |
last post by:
Assuming you had a template folder and files on the webspace and you
wanted to make a exact copy/rename of it with a username and password
being the one and only difference - how would one do it ?...
|
by: Sourcerer |
last post by:
Hi all.
Can I do this to duplicate the contents of struct a in struct b
struct myStruct a, b, *aptr, *bptr;
aptr = a;
bptr = b;
Do something to initialize contents of structure a...
|
by: Steve Franks |
last post by:
The Copy Web tool provided with VS.NET 2005 is very convenient. However
every once in a while it seems to think the files on the remote server have
changed, which they have not. Then when I use...
|
by: luis molina Micasoft |
last post by:
it seems that when i do file.copy the svchost.exe is hanged, i mean if i make
40 threads of file.copy , 40 copys of files at same time the system is going
down and stop responding, this is when i'm...
|
by: MarkusR |
last post by:
Good day,
I need to safely copy files from one directory to another. I need to
make sure that I do not lock the file making it unreadable by others.
I am not sure if this is the default...
|
by: surimca2002 |
last post by:
How do u copy multiple files from a lsbox to somewhere else? Does a
CopyFile
method work in this case? If so, how do I manage to copy multiple
files?
using vb.net
pls give me solutions...
|
by: mridulmurari |
last post by:
Hey. I need help with a certain problem I'm facing in VB6. I need to display the contents of multiple items in a listview.
The situation is this : Everytime i double-click on an item in a...
|
by: jonathan184 |
last post by:
Hi I am trying to copyfiles and dirs keeping there permissions intact and copy to multiple destinations which are on a data.txt file
on the txt file i put
test1
test2
So where ami going wrong?...
|
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= |
last post by:
Using .NET 2.0 is it more efficient to copy files to a single folder versus
spreading them across multiple folders.
For instance if we have 100,000 files to be copied,
Do we copy all of them to...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |