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