JAvaによるファイルの操作


詳細
JAvaフォルダファイルの遍歴:
package com.mixian.file;

import java.io.File;

public class getAllname {

	public static void main(String[] args) {
		File fileDir  = new File("c:/");
			File[] files = fileDir.listFiles();
			for(int i = 0; i 
 

  :

package com.mixian.file;

import java.io.IOException;
import java.io.InputStream;

public class inStreamTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		InputStream is = System.in;
		byte[] bt = new byte[1024];
		try {
			 is.read(bt);  //          
			 System.out.println("xx"+new String(bt).trim());
				is.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

}

 
は ています.
OutputStream out = System.out;
		try {
			out.write("12".getBytes());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

 ファイル を み みます.
try {
			FileInputStream is = new FileInputStream("c:/new.txt");
			int length;
			byte[] by = new byte[1024];
			try {
				while((length = is.read(by))!=-1){
					String str = new String(by,0,length);
					System.out.println(str);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

 ファイルの き み:
File file = new File("c:/mixian.txt");
		if(!file.exists()){
			file.createNewFile();
		}
		
		FileOutputStream out = new FileOutputStream(file);
		byte[] byx = "test out".getBytes();
		out.write(byx);
		out.close();

  の :
	//           ,            
		InputStreamReader isr = new InputStreamReader(System.in);
		char[] chars = new char[100];
		isr.read(chars);
		//int str = isr.read(chars);
		String str = new String(chars);
		System.out.println(str.trim());

 ファイルの み み:
//    
		FileReader reader = new FileReader("c:/mixian.txt");
		int length;
		while((length = reader.read())!=-1){
			System.out.println((char)length);
		}