繁体   English   中英

如何在属性文件中写入?

[英]how can I write in properties file?

我有一个属性文件“jpg2dcm.cfg”,属性默认设置。 所以,我必须添加属性值。如何修改文件以使用 java 在其中设置属性值?

jpg2dcm.cfg :

# jpg2dcm Default Configuration for encapsulating JPEG Baseline streams into
# DICOM Secondary Capture Image objects
# (s. DICOM Part 3, A.32.7 Video Photographic Image IOD)

# Patient Module Attributes
# Patient's Name
00100010:
# Patient ID
00100020:
# Issuer of Patient ID
#00100021:
# Patient's Birth Date
00100030:
# Patient's Sex
00100040:

# General Study Module Attributes
# Study Instance UID
#0020000D:
# Study Date
00080020:
# Study Time
00080030:
# Referring Physician's Name
00080090:
# Study ID
00200010:
# Accession Number
00080050:
# Study Description
#00081030:

# General Series Module Attributes
# Modality
00080060:OT
# Series Instance UID
#0020,000E:
# Series Number
00200011:1

# General Equipment Module Attributes
# Manufacturer
00080070:

# SC Equipment Module Attributes
# Conversion Type
00080064:SI

# General Image Module Attributes
# Instance Number
00200013:1

# Image Pixel Module Attributes (detected from JPEG file, if not specified)
# Samples per Pixel
#00280002:3
# Photometric Interpretation
#00280004:YBR_FULL_422
# Planar Configuration
#00280006:0
# Rows
#00280010:
# Columns
#00280011:
# Bits Allocated
#00280100:8
# Bits Stored
#00280101:8
# High Bit
#00280102:7
# Pixel Representation
#00280103:0

# SOP Common Module Attributes
# SOP Class UID
00080016:1.2.840.10008.5.1.4.1.1.7
# SOP Instance UID
#00080018

使用 FileReader 读取文件,如下所示:

FileReader fileReader = new FileReader(filename); 
BufferedReader br = new BufferedReader(fileReader); 
String line; 
while((line= br.readLine()) != null) { 
System.out.println(line);
//Do what you need after reading the file.
} 
fileReader.close();

修改字符串后,您需要修改或使用它完成您需要的工作,只需在同一位置写入一个具有相同名称的新文件,如下所示:

FileWriter writer = new FileWriter(filename);
writer.write(newStringToWriteInFile);
writer.close();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM