Tag: io

我如何创build一个文件并在Java中写入?

用Java创build和写入(文本)文件最简单的方法是什么?

如何从文件内容创buildJavastring?

我已经使用了一段时间以下的习语。 这似乎是最广泛的,至less在我访问的网站。 有没有更好的/不同的方式来读取文件到Java中的string? private String readFile(String file) throws IOException { BufferedReader reader = new BufferedReader(new FileReader (file)); String line = null; StringBuilder stringBuilder = new StringBuilder(); String ls = System.getProperty("line.separator"); try { while((line = reader.readLine()) != null) { stringBuilder.append(line); stringBuilder.append(ls); } return stringBuilder.toString(); } finally { reader.close(); } }

用Java读取纯文本文件

看来有不同的方法来读取和写入Java文件的数据。 我想从文件中读取ASCII数据。 什么是可能的方式和差异?

如何将文本追加到Java中的现有文件

我需要将文本重复附加到Java中的现有文件。 我怎么做?

扫描仪使用next(),nextInt()或其他nextFoo()后跳过nextLine()?

我正在使用Scanner方法nextInt()和nextLine()来读取input。 基本上,它看起来像这样: System.out.println("enter numerical value"); int option; option = input.nextInt();//read numerical value from input System.out.println("enter 1st string"); String string1 = input.nextLine();//read 1st string (this is skipped) System.out.println("enter 2nd string"); String string2 = input.nextLine();//read 2nd string (this appears right after reading numerical value) 问题是,input数值后,第一个input.nextLine()被跳过,第二个input.nextLine()被执行,所以我的输出如下所示: Enter numerical value 3 //this is my input enter 1st string //the […]

如何添加一个超时Console.ReadLine()?

我有一个控制台应用程序,我想让用户x秒响应提示。 如果在一段时间后没有输入,程序逻辑应该继续。 我们假设超时意味着空的回应。 什么是最直接的方法来解决这个问题?

用Python写一个列表到一个文件

这是最清洁的方式写一个列表文件,因为writelines()不插入换行符? file.writelines(["%s\n" % item for item in list]) 看来会有一个标准的方式…

你如何确定在C文件的大小?

我怎样才能算出一个文件的大小,以字节为单位? #include <stdio.h> unsigned int fsize(char* file){ //what goes here? }