/*
 * [TestParent.java]
 *
 * Summary: Explore how File.getParent works.
 *
 * Copyright: (c) 2016-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.8+
 *
 * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
 *
 * Version History:
 *  1.0 2016-08-23 initial version
 */
package com.mindprod.example;

import java.io.File;
import java.io.IOException;

import static java.lang.System.*;

/**
 * Explore how File.getParent works.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2016-08-23 initial version
 * @since 2010-02-20
 */
public final class TestParent
    {
    /**
     * Explore how File.getParent works.
     *
     * @param args not used
     */
    public static void main( String[] args ) throws IOException
        {
        // presume CWD is C:\temp
        final File plain = new File( "temp.txt" );
        out.println( plain.exists() ? "exists" : "missing" );
        out.println( plain.getParent() );
        // prints null whether temp.txt exists or not
        final File qualifiedDir = new File( "C:\\Users\\Public\\" );
        out.println( qualifiedDir.getParent() );
        // prints C:\Users
        final File qualifiedFile = new File( "C:\\Windows\\System32\\drivers\\etc\\hosts." );
        out.println( qualifiedFile.getParent() );
        // prints C:\Windows\System32\drivers\etc
        final File noDriveFile = new File( "\\Windows\\System32\\drivers\\etc\\hosts." );
        out.println( noDriveFile.getParent() );
        // prints \Windows\System32\drivers\etc
        final File slashFile = new File( "C:/Windows/System32/drivers/etc/hosts." );
        out.println( slashFile.getParent() );
        // prints C:\Windows\System32\drivers\etc, with \ not /
        // The key to understanding is getParent does not examine the file system or the CWD.
        // It justs hands you back a substring of the filename.
        // A rule of thumb is, always feed it Files with fully qualified names.
        }
    }