1
다음 코드를 통해 속성 파일의 값을 업데이트하려고합니다.속성 파일을 읽고 저장하는 중
import java.io. *; 가져 오기 java.util.Properties;
public class Sample {
public static void main(String a[]) throws IOException {
InputStream is = Sample.class.getClassLoader().getResourceAsStream("myfile.properties");
Properties p = new Properties();
p.load(is);
p.setProperty("myProperty", "updated");
OutputStream os = new FileOutputStream("myfile.properties");
p.store(os, "update");
os.close();
System.out.print(p.getProperty("myProperty"));
}
}
출력 :
를 업데이트하지만 값을 업데이 트하지 않는 것 같습니다. 사실, 속성이나 파일 자체가 없어도 오류가 발생하지 않습니다.
이 등록 정보 파일은 JAR에서 buldled입니까? –
아니요, 저는 그것들 모두를 별도의 디렉토리에 넣었습니다. – sweetcode