如何在属性文件中写入?

时间:2016-04-04 20:32:08

标签: java

我有一个属性文件“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

1 个答案:

答案 0 :(得分:0)

使用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();