aspose file tools*
The moose likes Beginning Java and the fly likes another Question of java.io Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "another Question of java.io" Watch "another Question of java.io" New topic
Author

another Question of java.io

Muddassir Sayeed
Greenhorn

Joined: Jul 08, 2001
Posts: 7
import java.io.*;
public class fileOutput
{
public static void main(String args[])
{
String fn = "d:/new/net.txt";
File f1 = new File(fn);
try
{
f1.createNewFile();
FileOutputStream fStream = new FileOutputStream(f1, true);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
why cant I run this code in jdk 1.3??? but the same code with different variables are wirtten in IVOR HOrton book.
Waiting For Reply
Muddassir Sayeed
John Fairbairn
Ranch Hand

Joined: May 30, 2002
Posts: 55

I don't believe the code will compile.
Here you are passing a File object and boolean as parameters to the constructor for the FileOutputStream object. This is not valid. You can pass a String (pathname to file) and a boolean if you want. The javadoc for FileOutputStream shows the valid ways to construct this object.
Muddassir Sayeed
Greenhorn

Joined: Jul 08, 2001
Posts: 7
Thanks For the reply . yes you are right. This code will run on JDK 1.4 which allow File object as argument, but here i am writing the code from the book IVOR Horton which is confusing me.
String filename = "myFile.txt";
File aFile = new File(filename);
try
{
aFile.createNewFile();
FileOutputStream file1 = new FileOutputStream(aFile, true);
}
catch(IOException e)
{
System.out.println(e);
}

This is the code which is written in the ivor Horton's book by name Beginning JAVA 2 (JDK 1.3 Edition). please answer me. hope your answers will help me and make be able to understand this code. May be this is the error of the book
Muddassir Sayeed

[ July 11, 2002: Message edited by: Muddassir Sayeed ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
It's a known error. See the errata.


"I'm not back." - Bill Harding, Twister
Muddassir Sayeed
Greenhorn

Joined: Jul 08, 2001
Posts: 7
Thanks for helping me
Muddassir Sayeed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: another Question of java.io