Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Append in File with JDK 1.3  RSS feed

 
Sameer sam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I am in a situation where I have to read a file with chunks andwrite each chunk in another file.If other file file does not exist then create it else append data tothe end of file.
Now the problem is how to achieve this append functionality in JDK1.3.

I mean i would like to open a file and append some data in it.
can any help me in solvinf this issue

Thanks,
Sameer
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the various contructors for FileOutputStream (for binary data) or FileWriter (for text data). You'll find some in each class that take an "append" argument so that data will add to an existing file instead of truncating it.
 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sameer sam:
hi,

I am in a situation where I have to read a file with chunks andwrite each chunk in another file.If other file file does not exist then create it else append data tothe end of file.
Now the problem is how to achieve this append functionality in JDK1.3.

I mean i would like to open a file and append some data in it.
can any help me in solvinf this issue

Thanks,
Sameer


You can use the FileWriter class.
http://java.sun.com/j2se/1.3/docs/api/java/io/FileWriter.html

FileWriter(String fileName, boolean append)
Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.
 
Sameer sam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I have been using File constructor with two parameters file name and append (boolean value).It is working fine on JDK1.4 .
On JDK1.3 it compiles but at runtime it give error (NoSuchMethodFound error )
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15859
80
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you are compiling it with the JDK 1.3 compiler? If you are calling a method that doesn't exist in Java 1.3, the compiler would complain about it and you'd get a compiler error, not a runtime error.

It sounds like you've compiled your source code with the 1.4 compiler or against the 1.4 class libraries, and you're running it on 1.3.
 
Sameer sam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a sample code that comiple on JDK1.3.1_01 and doesn't run

Execption is

Exception in thread "main" java.lang.NoSuchMethodError
at TestFile.main(TestFile.java:11)
------------------------------------------------------

import java.io.*;
public class TestFile{
public static void main(String[] args) {
File outFile=null;
FileOutputStream fout= null;
try
{
File directory=new File("c:/folder1");
directory.mkdirs();
outFile=new File("c:/folder1","checkABC.txt");
FileWriter fw=new FileWriter(outFile,true);
fw.write(55);
// fout = new FileOutputStream(outFile,true);
//fout.write(50);
}
catch(Exception e)
{
e.printStackTrace();
}
}

}
 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sameer sam:
outFile=new File("c:/folder1","checkABC.txt");
FileWriter fw=new FileWriter(outFile,true);
}

}


There is no way that can compile in 1.3. The FileWriter constructor should read



-Rajagopal
 
Sameer sam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your help.Now it is working perfectly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!