Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ʹÓÃJava²Ù×÷Îı¾ÎļþµÄ·½·¨Ïê½â(ת)

   ×î³õJavaÊDz»Ö§³Ö¶ÔÎı¾ÎļþµÄ´¦ÀíµÄ£¬ÎªÁËÃÖ²¹Õâ¸öȱº¶¶øÒýÈëÁËReaderºÍWriterÁ½¸öÀ࣬ÕâÁ½¸öÀ඼ÊdzéÏóÀ࣬WriterÖÐwrite(char[] ch,int off,int length)£¬flush()ºÍclose()·½·¨Îª³éÏó·½·¨£¬ReaderÖÐread(char[] ch,int off,int length)ºÍclose()·½·¨ÊdzéÏó·½·¨¡£×ÓÀàÓ¦¸Ã·Ö±ðʵÏÖËûÃÇ¡£
¡¡¡¡µ±ÎÒÃǶÁдÎı¾ÎļþµÄʱºò£¬²ÉÓÃReaderÊǷdz£·½±ãµÄ£¬±ÈÈçFileReader£¬InputStreamReaderºÍBufferedReader¡£ÆäÖÐ×îÖØÒªµÄÀàÊÇInputStreamReader£¬ËüÊÇ×Ö½Úת»»Îª×Ö·ûµÄÇÅÁº¡£Äã¿ÉÒÔÔÚ¹¹ÔìÆ÷ÖØÖ¸¶¨±àÂëµÄ·½Ê½£¬Èç¹û²»Ö¸¶¨µÄ»°½«²ÉÓõײã²Ù×÷ϵͳµÄĬÈϱàÂ뷽ʽ£¬ÀýÈçGBKµÈ¡£µ±Ê¹ÓÃFileReader¶ÁÈ¡ÎļþµÄʱºò¡£
FileReader fr = new FileReader("ming.txt");
int ch = 0;
while((ch = fr.read())!=-1 )
{
¡¡System.out.print((char)ch);
}
¡¡¡¡ÆäÖÐread()·½·¨·µ»ØµÄÊǶÁÈ¡µÃϸö×Ö·û¡£µ±È»ÄãÒ²¿ÉÒÔʹÓÃread(char[] ch,int off,int length)ÕâºÍ´¦Àí¶þ½øÖÆÎļþµÄʱºòÀàËÆ£¬²»¶à˵ÁË¡£Èç¹ûʹÓÃInputStreamReaderÀ´¶ÁÈ¡ÎļþµÄʱºò
while((ch = isr.read())!=-1)
{
¡¡System.out.print((char)ch);
}
¡¡¡¡ÕâºÍFileReader²¢Ã»ÓÐʲôÇø±ð£¬ÊÂʵÉÏÔÚFileReaderÖеķ½·¨¶¼ÊÇ´ÓInputStreamReaderÖм̳йýÀ´µÄ¡£read()·½·¨ÊDZȽϺ÷Ñʱ¼äµÄ£¬Èç¹ûΪÁËÌá¸ßЧÂÊÎÒÃÇ¿ÉÒÔʹÓÃBufferedReader¶ÔReader½øÐаü×°£¬ÕâÑù¿ÉÒÔÌá¸ß¶ÁÈ¡µÃËٶȣ¬ÎÒÃÇ¿ÉÒÔÒ»ÐÐÒ»ÐеĶÁÈ¡Îı¾£¬Ê¹ÓÃreadLine()·½·¨¡£
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("ming.txt")));
String data = null;
while((data = br.readLine())!=null)
{
¡¡System.out.println(data);
}
¡¡¡¡µ±ÄãÃ÷°×ÁËÈçºÎÓÃReaderÀ´¶ÁÈ¡Îı¾ÎļþµÄʱºòÄÇôÓÃWriterдÎļþͬÑù·Ç³£¼òµ¥¡£ÓÐÒ»µãÐèҪעÒ⣬µ±ÄãдÎļþµÄʱºò£¬ÎªÁËÌá¸ßЧÂÊ£¬Ð´ÈëµÄÊý¾Ý»áÏÈ·ÅÈ뻺³åÇø£¬È»ºóдÈëÎļþ¡£Òò´ËÓÐʱºòÄãÐèÒªÖ÷¶¯µ÷ÓÃflush()·½·¨¡£ÓëÉÏÃæ¶ÔÓ¦µÄдÎļþµÄ·½·¨Îª£º
FileWriter fw = new FileWriter("hello.txt");
String s = "hello world";
fw.write(s,0,s.length());
fw.flush();
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("hello2.txt"));
osw.write(s,0,s.length());
osw.flush();
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("hello3.txt")),true);
pw.println(s);
¡¡¡¡²»ÒªÍü¼ÇÓÃÍê


Ïà¹ØÎĵµ£º

Java NIO APIÏê½â

 
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......

Java°´×Ö½Ú³¤¶È½ØÈ¡×Ö·û´®


±à³Ì£º±àдһ¸ö½ØÈ¡×Ö·û´®µÄº¯Êý£¬ÊäÈëΪһ¸ö×Ö·û´®ºÍ×Ö½ÚÊý£¬Êä³öΪ°´×Ö½Ú½ØÈ¡µÄ×Ö·û´®¡£µ«ÊÇÒª±£Ö¤ºº×Ö²»±»½Ø°ë¸ö£¬Èç"ÎÒABC"4£¬Ó¦¸Ã½ØΪ"ÎÒAB"£¬ÊäÈë"ÎÒABCººDEF"£¬6£¬Ó¦¸ÃÊä³öΪ"ÎÒABC"¶ø²»ÊÇ"ÎÒABC+ººµÄ°ë¸ö"¡£
¡¡¡¡public static String substring(String str, int toCount,String& ......

JAVA½ø½×£ºÒ»¸ö¼òµ¥Thread»º³å³ØµÄʵÏÖ


ÔÚÓ¦ÓÃÖУ¬ÎÒÃdz£³£ÐèÒªThread»º³å³ØÀ´×öһЩÊÂÒÔÌá¸ß³ÌÐòµÄЧÂʺͲ¢·¢ÐÔ¡£±¾ÎÄÑÝʾÁËÈçºÎÀûÓÃQueueÕâÖÖÊý¾Ý½á¹¹ÊµÏÖÒ»¸ö¼òµ¥µÄThread»º³å³Ø¡£
Ò»¸öThread»º³å³Ø¿ÉÒÔÉè¼Æ³ÉÒÔÏÂÕâÑù£º»º³å³ØÓɼ¸¸ö¹¤×÷ThreadºÍÒ»¸öQueue×é³É£¬Client¸ºÔð°ÑÈÎÎñ·Åµ½QueueÀïÃ棨put·½·¨£©£¬¶ø¹¤×÷Thread¾ÍÒÀ´ÎÈ¡³öÕâЩÈÎÎñ²¢Ö´ÐÐËüÃÇ£¨get· ......

JavaʵÏÖ£ºÎļþ´«Êä

//´úÂë¾­¹ý±àÒ룬ÔËÐУ¬Ö¤Ã÷¿ÉÒÔÔËÐÐ
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.net.*;
import javax.swing.filechooser.FileFilter;
public class Ftp extends JLabel
{
 private JButton openButton;
 privat ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ