• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

another Question of java.io

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a known error. See the errata.
 
Muddassir Sayeed
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for helping me
Muddassir Sayeed
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic