- Äɲ䵤줿¹Ô¤Ï¤³¤Î¿§¤Ç¤¹¡£
- ºï½ü¤µ¤ì¤¿¹Ô¤Ï¤³¤Î¿§¤Ç¤¹¡£
[[java]]
¤½¤ì¤¾¤ì¡¢¼¡¤Îimport¤¬É¬ÍפǤ¹¡£
import java.io.*;
*¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß [#x3a019d8]
import java.io.*;
FileReader fr;
try {
FileReader fr = new FileReader("¥Õ¥¡¥¤¥ë̾");
fr = new FileReader("¥Õ¥¡¥¤¥ë̾");
int c;
String str = new String();
while ((c = fr.read()) != -1) {
str = str + (char)c;
}
fr.close();
} catch (IOException e) {
System.err.println(e);
} finally {
try {
if (fr != null) {
fr.close();
fr = null;
}
} catch (IOException e2) {
}
}
*¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë½ñ¤¹þ¤ß [#q81cfda2]
import java.io.*;
FileWriter fw;
try {
FileWriter fw = new FileWriter("¥Õ¥¡¥¤¥ë̾");
fw = new FileWriter("¥Õ¥¡¥¤¥ë̾");
fw.write("½ñ¤¹þ¤ß¤¿¤¤Ê¸»úÎó");
fw.close();
} catch (IOException e) {
System.err.println(e);
} finally {
try {
if (fw != null) {
fw.close();
fw = null;
}
} catch (IOException e2) {
}
}
*¥Ð¥Ã¥Õ¥¡ÉÕ¤¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß [#b48c9a14]
import java.io.*;
BufferedReader br;
try {
FileReader fr = new FileReader("¥Õ¥¡¥¤¥ë̾");
BufferedReader br = new BufferedReader(fr);
br = new BufferedReader(new FileReader("¥Õ¥¡¥¤¥ë̾"));
String str = new String();
while ((str = br.readLine()) != null) {
System.out.println(str); // ½èÍý¤òµ½Ò
}
br.close();
} catch (IOException e) {
System.err.println(e);
} finally {
try {
if (br != null) {
br.close();
br = null;
}
} catch (IOException e2) {
}
}
*¥Ð¥Ã¥Õ¥¡ÉÕ¤¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë½ñ¤¹þ¤ß [#m968c57c]
import java.io.*;
BufferedWriter bw;
try {
FileWriter fw = new FileWriter("¥Õ¥¡¥¤¥ë̾");
BufferedWriter fr = new BufferedWriter(fw);
bw = new BufferedWriter(new FileWriter("¥Õ¥¡¥¤¥ë̾"));
bw.write(½ñ¤¹þ¤ß¤¿¤¤¥Ç¡¼¥¿);
bw.newLine; // ¹Ô¶èÀÚ¤ê
bw.flush;
bw.close();
bw.flush();
} catch (IOException e) {
System.err.println(e);
} finally {
try {
if (bw != null) {
bw.close();
bw = null;
}
} catch (IOException e2) {
}
}
*¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë byteñ°Ì¤ÎÆɤ߹þ¤ß [#f17e89cd]
import java.io.*;
FileInputStream fis;
try {
FileInputStream fis = new FileInputStream("¥Õ¥¡¥¤¥ë̾");
fis = new FileInputStream("¥Õ¥¡¥¤¥ë̾");
int b;
while ((b = fis.read()) != -1) {
System.out.println(b); // ½èÍý¤òµ½Ò
}
fis.close();
} catch (FileNotFoundException e) {
System.err.println(e);
} catch (IOException e) {
System.err.println(e);
} finally {
try {
if (fis != null) {
fis.close();
fis = null;
}
} catch (IOException e2) {
}
}
*¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë byteñ°Ì¤Î½ñ¤¹þ¤ß [#j699091b]
import java.io.*;
FileOutputStream fos;
try {
FileOutputStream fos = new FileOutputStream("¥Õ¥¡¥¤¥ë̾");
fos = new FileOutputStream("¥Õ¥¡¥¤¥ë̾");
fos.write(½ñ¤¹þ¤ß¤¿¤¤¥Ç¡¼¥¿);
fos.close();
} catch (FileNotFoundException e) {
System.err.println(e);
} catch (IOException e) {
System.err.println(e);
} finally {
try {
if (fos != null) {
fos.close();
fos = null;
}
} catch (IOException e2) {
}
}
*¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë³Æ¼ï¥Ç¡¼¥¿Æɤ߹þ¤ß [#q4d3886d]
import java.io.*;
DataInputStream dis;
try {
FileInputStream fis = new FileInputStream("¥Õ¥¡¥¤¥ë̾");
DataInputStream dis = new DataInputStream(fis);
dis = new DataInputStream(new BufferedInputStream(new FileInputStream("¥Õ¥¡¥¤¥ë̾")));
// dis = new DataInputStream(new FileInputStream("¥Õ¥¡¥¤¥ë̾")); ¥Ð¥Ã¥Õ¥¡Ìµ¤·¤Î¾ì¹ç
int i = dis.readInt();
String str = dis.readUTF();
dis.close();
} catch (FileNotFoundException e) {
System.err.println(e);
} catch (IOException e) {
System.err.println(e);
} finally {
try {
if (dis != null) {
dis.close();
dis = null;
}
} catch (IOException e2) {
}
}
*¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë³Æ¼ï¥Ç¡¼¥¿½ñ¤¹þ¤ß [#hbde2777]
import java.io.*;
DataOutputStream dos;
try {
FileOutputStream fos = new FileOutputStream("¥Õ¥¡¥¤¥ë̾");
DataOutputStream dos = new DataOutputStream(fos);
dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("¥Õ¥¡¥¤¥ë̾")));
// dos = new DataOutputStream(new FileOutputStream("¥Õ¥¡¥¤¥ë̾")); ¥Ð¥Ã¥Õ¥¡Ìµ¤·¤Î¾ì¹ç
dos.writeInt(½ñ¤¹þ¤ß¤¿¤¤int·¿¥Ç¡¼¥¿);
dos.writeUTF(½ñ¤¹þ¤ß¤¿¤¤Ê¸»úÎó¥Ç¡¼¥¿);
dos.close();
} catch (FileNotFoundException e) {
System.err.println(e);
} catch (IOException e) {
System.err.println(e);
} finally {
try {
if (dos != null) {
dos.close();
dos = null;
}
} catch (IOException e2) {
}
}