Path: blob/master/test/jdk/java/util/Properties/LoadSeparators.java
41152 views
/*1* Copyright (c) 2018, 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 419267826* @summary Test loading of values that are key value separators27*/2829import java.io.File;30import java.io.FileInputStream;31import java.io.FileOutputStream;32import java.io.IOException;33import java.util.Properties;3435/**36* This class tests to see if a properties object can successfully save and37* load properties with a non-escaped value that is also a key value separator38*39*/40public class LoadSeparators {41public static void main(String[] argv) throws Exception {42try {43// Destroy old test file if any44// Create a properties file45File propFile = new File("testout");46propFile.delete();4748// Create a properties file49FileOutputStream myOut = new FileOutputStream(propFile);50String testProperty = "Test3==";51myOut.write(testProperty.getBytes());52myOut.close();5354// Load the properties set55FileInputStream myIn = new FileInputStream("testout");56Properties myNewProps = new Properties();57try {58myNewProps.load(myIn);59} finally {60myIn.close();61}6263// Read in the test property64String equalSign = myNewProps.getProperty("Test3");6566// Clean up67propFile.delete();6869if (!equalSign.equals("="))70throw new Exception("Cannot read key-value separators.");71} catch (IOException e) {72System.err.println(e);73}74}75}767778