Path: blob/master/test/jdk/java/io/pathNames/win32/RenameDelete.java
41153 views
/*1* Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4042592 404259326* @summary Test operation of rename and delete on win3227*/2829import java.io.*;3031/**32* This class tests to see if java.io.file rename() method33* operates properly with non canonical pathnames34* and then tests delete() method with non canonical pathnames35*/3637public class RenameDelete {3839public static void main(String[] args) throws Exception {40boolean success = false;4142if (File.separatorChar != '\\') {43System.err.println("Not a win32 platform -- test inapplicable");44return;45}4647//construct a test file in this location48File f1 = new File(".");49StringBuffer location = new StringBuffer("\\");50location.append(f1.getCanonicalPath());5152StringBuffer fromLocation = new StringBuffer(location.toString()+"\\From");53StringBuffer toLocation = new StringBuffer(location.toString()+"\\To");5455f1 = new File(fromLocation.toString());56File f2 = new File(toLocation.toString());5758if(f1.exists() || f2.exists()) {59System.err.println("Directories exist -- test not valid");60return;61}6263System.err.println("Create:"+f1.mkdir());64System.err.println("Exist as directory:"+f1.exists()+" "+f1.isDirectory());65success = f1.renameTo(f2);66System.err.println("Rename:"+success);6768if (!success)69throw new RuntimeException("File method rename did not function");7071success = f2.delete();72System.err.println("Delete:"+success);7374if (!success)75throw new RuntimeException("File method delete did not function");7677}7879}808182