Hej Andreas,
Prøv at udskifte:
- import java.io.*;
-
- public class Udlån {
-
- public static void main(String[] args) {
- File fil = new File("c:\\hej.txt");
- boolean b;
- try {
- b = fil.createNewFile();
- System.out.print("" + fil..getAbsolutePath());
- }
- catch(IOException e) {
- System.out.print("" + fil..getAbsolutePath());
- System.out.println("EXCEPTION: " + e);
- }
- catch(Exception e) {
- System.out.print("General Exception: ");
- System.out.print("" + fil..getAbsolutePath());
- System.out.println("EXCEPTION: " + e);
- }
- if(b = true) {
- System.out.println("true");
- }
- }
- }
Skriv så derefter hvad den skriver her i tråden. Det kan give dig et hint.
Derudover har jeg et stort eksempel:
- import java.io.*;
-
- public class Program
- {
- public static void main(String[] args)
- {
- try
- {
- // Open the file C:\MyFile.txt.
- File myFile = new File("C:\\MyFile.txt");
- if (myFile.exists())
- {
- System.out.println(myFile.getAbsolutePath() +
- " already exists.");
- }
- else
- {
- if (myFile.createNewFile())
- {
- System.out.println("Created file " +
- myFile.getAbsolutePath());
- }
- else
- {
- System.out.println("Unable to create file " +
- myFile.getAbsolutePath());
- }
- }
-
- // Open the file C:\DoesNotExist.txt.
- File noFile = new File ("C:\\DoesNotExist.txt");
- if (noFile.exists())
- {
- System.out.println(noFile.getAbsolutePath() +
- " already exists.");
- }
- else
- {
- if (noFile.createNewFile())
- {
- System.out.println("Created file " +
- noFile.getAbsolutePath());
- }
- else
- {
- System.out.println("Unable to create file " +
- noFile.getAbsolutePath());
- }
- }
- }
- catch (IOException ex)
- {
- System.out.println(ex.toString());
- }
- }
- }
Med venlig hilsen
Ieet
Indlæg senest redigeret d. 07.08.2008 11:50 af Bruger #12836