Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

another Question of java.io

 
Muddassir Sayeed
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a known error. See the errata.
 
Muddassir Sayeed
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for helping me
Muddassir Sayeed
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic