Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我需要用java编写一个文件_Java_Makefile - Fatal编程技术网

我需要用java编写一个文件

我需要用java编写一个文件,java,makefile,Java,Makefile,这是我的密码 /* *要更改此许可证标题,请在“项目属性”中选择“许可证标题”。 *要更改此模板文件,请选择工具|模板 *然后在编辑器中打开模板。 */ 包名读取器; 导入java.util.*; 导入java.io.*; /** * *@author jpowell1225 */ 公共类名称读取器{ /** *@param指定命令行参数 */ 公共静态无效主字符串[]args引发IOException{ //此处的TODO代码应用程序逻辑 布尔onoff=true; 整数计数=0; int

这是我的密码

/* *要更改此许可证标题,请在“项目属性”中选择“许可证标题”。 *要更改此模板文件,请选择工具|模板 *然后在编辑器中打开模板。 */ 包名读取器; 导入java.util.*; 导入java.io.*; /** * *@author jpowell1225 */ 公共类名称读取器{ /** *@param指定命令行参数 */ 公共静态无效主字符串[]args引发IOException{ //此处的TODO代码应用程序逻辑 布尔onoff=true; 整数计数=0; int count2=0; 字符串first=null; FileWriter fw=新FileWriterText,true; 字符串last=null; 扫描仪扫描=新的ScannerSystem.in; scan.useDelimiter; //scan.useDelimiter; 呼啸而过{ first=scan.nextLine; 如果第一个相等,则退出{ 打破 } fw.writefirst; FileReader fr=新的FileReaderText; 扫描仪src=新的扫描仪FR; count=first.lastIndexOf; count2=first.indexOf,2; System.out.println您的名字是:+first.substringcount++first.substringcount2,count2+2+。+first.substring0,count2; } fw.close; 扫描。关闭; } } 您忘记像这样刷新输出流

fw.flush();//flush it before close it.
fw.close();
您也可以使用try{},让Java自动关闭FileWriter

编辑 尝试{}是自java1.7以来的一个新方案,用于让jvm在块之后自动关闭可关闭对象。在你的代码中可能是这样的

try(Scanner scan = new Scanner(System.in);FileWriter fw = new FileWriter("txt",true);){
//using the objects
}//jre will closes both :scan and :fw objects automatically

使用fw.flush对我没有任何帮助,但是你能告诉我如何格式化我的代码,使我可以使用try{}吗?我在这方面是个新手:P