【发布时间】:2017-08-23 06:28:36
【问题描述】:
获得已安装程序的列表后,我将它们全部写入 pro.txt 文件。
String filename="C:\\Users\\Zeeshan\\Desktop\\pro.txt";
FileWriter fileWriter =new FileWriter(filename);
BufferedWriter br =new BufferedWriter(fileWriter);
String command = "powershell.exe \"Get-ItemProperty HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Select-Object DisplayName | Format-Table –AutoSize\"";
Process p = Runtime.getRuntime().exec(command);
p.getOutputStream().close();
BufferedReader input =new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
int number=0;
while ((input.readLine()) != null)
{
line=input.readLine();
br.write(++number+"."+line);
br.newLine();
}
br.close();
input.close();
但是当我尝试使用缓冲读取器读取该文件时,每次输出后总是会丢失一行。
FileReader fr=new FileReader(filename);
BufferedReader br1=new BufferedReader(fr);
String line1;
while(br1.readLine()!=null)
{
line1=br1.readLine();
System.out.println(line1);
}
br1.close();
我的输出是这样的形式请也指导我为什么最后出现null。
2.
4.Google Chrome
6.RuntimePack 15.7.22
8.Scan
10.
12.
14.4500K710_Software_Min
16.Apple Software Update
18.Microsoft Visual C++ 2015 x86 Additional Runtime - 14.0.24215
20.WebReg
22.Update for Microsoft .NET Framework 4.6.1 (KB4014606)
24.Adobe Refresh Manager
26.Microsoft Visual C++ 2015 x86 Minimum Runtime - 14.0.24215
28.4500K710
30.Apple Application Support (32-bit)
32.
34.
36.BufferChm
null
【问题讨论】:
标签: java file bufferedreader bufferedwriter