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

📄 myfile.java

📁 主要是对于JAVA的编程的基本语言 希望能够帮得上你。
💻 JAVA
字号:
package ForTest;

import java.io.*;

public class MyFile {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		File f1=new File("io/flower.txt");
		try {
			f1.createNewFile();
		} catch (IOException e) {			
			e.printStackTrace();
		}
		
		File f2=new File("d://myjava/sun.txt");
		try {
			f2.createNewFile();
		} catch (IOException e) {			
			e.printStackTrace();
		}
		
		File f3=new File("d://myjava/","grass.txt");
		try {
			f3.createNewFile();
		} catch (IOException e) {			
			e.printStackTrace();
		}
		
		File f4=new File("io/","grass.txt");
		try {
			f4.createNewFile();
		} catch (IOException e) {			
			e.printStackTrace();
		}
		
		File f5=new File("d://我爱");
		f5.mkdir();		
		
		File f6=new File("d://我爱/北京");
		f6.mkdir();
		
		File f7=new File("d://我爱/北京/天安门");
		f7.mkdir();
		
		
		File f8=new File(f7,"毛泽东.txt");
		try {
			f8.createNewFile();			
			f8.deleteOnExit();
		} catch (IOException e) {			
			e.printStackTrace();
		}	
		
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			FileWriter fw=new FileWriter(f8);
			fw.write("我爱中国人民。");
			fw.flush();
		} catch (IOException e) {			
			e.printStackTrace();
		}
		
		try {
			FileWriter fw=new FileWriter("d://我爱/北京/天安门/周恩来.txt");
			fw.write("我是总理。");
			fw.flush();
		} catch (IOException e) {			
			e.printStackTrace();
		}
		
		
		try {
			//文件输出流,创建一个有内容的文件
			FileOutputStream fos=new FileOutputStream("io/sun.txt");
			byte[] name={'I',' ','a','m',' ','s','u','n'};
			try {
				fos.write(name);
				fos.write(' ');
				fos.write(66);
			} catch (IOException e) {				
				e.printStackTrace();
			}
			
			//文件输入流,读取文件里的内容			
			FileInputStream fis=new FileInputStream("io/sun.txt");
			StringBuffer buffer=new StringBuffer();
			int i;
			try {
				while((i=fis.read())!=-1){
					buffer.append((char)i);
				}
			} catch (IOException e) {				
				e.printStackTrace();
			}
			System.out.println("sun.txt的内容如下:");
			System.out.println(buffer.toString());
			
		} catch (FileNotFoundException e) {			
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

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