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
Printable View
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
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.
can anyone please help me with the code?
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
# 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());
# }
# }
# }
#
# }
please help me out
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.
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