-
January 28th, 2010, 12:05 PM
#1
java file copying
hai
can any body just tell me how to copy paragraph by paragraph of one file to different files at a time in java? please help me in coding
thank you
-
January 28th, 2010, 12:24 PM
#2
Re: java file copying
1. Open the file to read in.
2. Open a file to write to.
3. Repeatedly read in a line and write it to the output file until the end of paragraph or end of file is found.
4. Close the output file.
5. If the end of paragraph was found go back to step 2.
6. Close the input file.
-
January 28th, 2010, 11:34 PM
#3
Re: java file copying
can anyone please help me with the code?
-
January 29th, 2010, 05:25 AM
#4
Re: java file copying
Certainly. Post up the code you've got so far, and explain which part you're stuck on and we'll help you fix it.
Programming is an explanatory activity...
R. Harper
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
January 29th, 2010, 10:13 AM
#5
Re: java 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();
# //String s;
# 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;
#
for(int i=0;sFile=="\n\n";i++){
#
#
#
# for(String targetFile : targetFiles){
# new CopierThread(sFileBytes,targetFile[i]).run();
#
# }
}
# sFileInputStream.close();
# }
#
# 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());
# }
# }
# }
#
# }
-
January 29th, 2010, 10:16 AM
#6
-
January 29th, 2010, 12:33 PM
#7
Re: java file copying
Ok, so that's your code. What part isn't working?
The more clearly you explain what you want to happen and what is actually happening (remembering to include all error messages and stack traces) the more likely someone is to be able to help you.
Posting the code in code tags so it stays formatted would also help.
-
January 29th, 2010, 02:11 PM
#8
Re: java file copying
Straightaway I can see a problem - all your code lines start with a '#', so none of it is valid Java.
If you want us to make the effort to help you, you're going to have to make a reasonable effort to help us do that. Posting valid Java code that (preferably) compiles is a good start. Explaining exactly what you're stuck on is essential.
Eighty percent of success is showing up...
W. Allen
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|