⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileoutputdemo.java

📁 JAVA学习源代码,大家可以好好参考,请多提宝贵意见
💻 JAVA
字号:
     //FileOutputDemo.java import java.io.*; public class FileOutputDemo{ public
     static void main(String args[]) { String  fileName="OutputFileExample.txt";
     File   file=new  File(fileName);   FileOutputStream  outputStream;   byte[]
     bufferArray=new byte[4096]; int b; StringBuffer str=new StringBuffer(); try
     {        outputStream=new        FileOutputStream(file);        try       {
     System.out.println("\nInput   file   content(Tab+Enter   to   exit):    ");
     //循环读入字符,Tab+Enter键结束    while((char)(b=System.in.read())!='\t'){
     str.append(String.valueOf((char)b));    }    //将读入的字符串转化为字节数组
     bufferArray=str.toString().getBytes();               //将读入的字符写入文件
     outputStream.write(bufferArray,0,str.length());   outputStream.close();   }
     catch  (IOException  exception)  {  System.out.println("I/O  Exception when
     writing   or   closing:   "+exception.toString());   }   }  catch(Exception
     exception){           System.out.println(exception.toString());           }
     System.out.println("The content has been saved to File "+fileName); } } 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -