读取文件并立即将其写入输出,逐字节,测试文件结束和计算时间 [英] Read the file and write it to output immediately, byte-by-byte, testing for the end of file and compute time

查看:79
本文介绍了读取文件并立即将其写入输出,逐字节,测试文件结束和计算时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何编码这个



How we can code this

The main method will:
Request the input file name.
Request the output file name.
Request the program "mode" (see below)
0 -- means the file(s) will be processed in character-by-character mode (see #2 below).
1 -- means the file(s) will be processed in line-by-line mode (see #3 below).
The character-by-character method will:
Open a simple text file.
Read the file and write it to output immediately, byte-by-byte, testing for the end of file marker.
Close the files.
Compute and display the wall-clock time (the "real-world" time) 
The line-by-line method will:
Open a simple text file (same file as 2 above) and an output file.
Read the file and write it to output immediately, line-by-line, testing for the end of file marker.
Close the files.
Compute and display the wall-clock time (the "real-world" time)
Run the program, use both modes. Compare the two results and explain the differences, if any. If none, explain why.





我尝试过:





What I have tried:

The main method will:
Request the input file name.
Request the output file name.
Request the program "mode" (see below)
0 -- means the file(s) will be processed in character-by-character mode (see #2 below).
1 -- means the file(s) will be processed in line-by-line mode (see #3 below).
The character-by-character method will:
Open a simple text file.
Read the file and write it to output immediately, byte-by-byte, testing for the end of file marker.
Close the files.
Compute and display the wall-clock time (the "real-world" time) 
The line-by-line method will:
Open a simple text file (same file as 2 above) and an output file.
Read the file and write it to output immediately, line-by-line, testing for the end of file marker.
Close the files.
Compute and display the wall-clock time (the "real-world" time)
Run the program, use both modes. Compare the two results and explain the differences, if any. If none, explain why.







我的问题是我在哪里放时钟和第二个问题我如何在我的else块中打开该文件,因为它给我编译错误。




My question is where do i put my time clock and second question how do i will open that file in my else block because its giving me compilation error.

推荐答案

由于您没有指定哪些不起作用,因此很难提供帮助。但是,如果要使用用户提供的文件名作为输入,则必须从删除变量名称周围的引号开始:



Since you do not specify what is not working it is difficult to help. However, if you want to use the filenames that the user has provided as input you must start with removing the quotation marks around the variables names:

inputStream = new FileReader(inputfile);
outputStream = new FileWriter(outputfile);





Then你当然必须为n = 1的情况添加代码。



Then you of course must add code for the n=1 case.


这篇关于读取文件并立即将其写入输出,逐字节,测试文件结束和计算时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆