2016-04-04 50 views
-3

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

“巫婆”你说?!无论如何......如果它只是一个文本文件,为什么不打开它来写作,进行更改并保存呢? – durbnpoisn

+0

而你并没有追随已经出现过的无数指南之一,因为.....? – redFIVE

+0

这是一个太宽泛的问题。你不知道该怎么做?将文件读入一个属性对象,操作它还是把它写回来? – Sid

回答

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