Trang 2 của 2 Đầu tiênĐầu tiên 12
Kết quả 11 đến 13 của 13
  1. #11
    Ngày tham gia
    Feb 2015
    Bài viết
    0

    Mã nguồn PHP:
    [color=#000000]
    package [/color][color=#007700]$[/color][color=#0000bb]32timhieuvelopfiletrongjava[/color][color=#007700]; [/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].[/color][color=#0000bb]bufferedreader[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].[/color][color=#0000bb]file[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].[/color][color=#0000bb]ioexception[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].[/color][color=#0000bb]inputstreamreader[/color][color=#007700]; public class [/color][color=#0000bb]baitap [/color][color=#007700]{public static [/color][color=#0000bb]string fname[/color][color=#007700]=[/color][color=#0000bb]null[/color][color=#007700];public static [/color][color=#0000bb]string fseek[/color][color=#007700]=[/color][color=#0000bb]null[/color][color=#007700];[/color][color=#0000bb]string diskname[/color][color=#007700];static [/color][color=#0000bb]string adddisk[/color][color=#007700];public static [/color][color=#0000bb]void main[/color][color=#007700]([/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]args[/color][color=#007700]) [/color][color=#0000bb]throws exception[/color][color=#007700]{[/color][color=#0000bb]bufferedreader br[/color][color=#007700]=new [/color][color=#0000bb]bufferedreader[/color][color=#007700](new [/color][color=#0000bb]inputstreamreader[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]));[/color][color=#0000bb]adddisk[/color][color=#007700]=[/color][color=#dd0000]"d:\\"[/color][color=#007700];[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nicholassoft windows [version beta]"[/color][color=#007700]+[/color][color=#dd0000]"
    "[/color][color=#007700]+[/color][color=#dd0000]"<c>16aug 2014"[/color][color=#007700]+[/color][color=#dd0000]"
    "[/color][color=#007700]+[/color][color=#0000bb]adddisk[/color][color=#007700]);for([/color][color=#0000bb]int j[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]j[/color][color=#007700]<[/color][color=#0000bb]100[/color][color=#007700];[/color][color=#0000bb]j[/color][color=#007700]++){[/color][color=#ff8000]//cho chuong trinh chay nhieu lan[/color][color=#0000bb]string cd[/color][color=#007700]=new [/color][color=#0000bb]string[/color][color=#007700]();[/color][color=#0000bb]cd[/color][color=#007700]=[/color][color=#0000bb]br[/color][color=#007700].[/color][color=#0000bb]readline[/color][color=#007700]();[/color][color=#0000bb]cd[/color][color=#007700].[/color][color=#0000bb]trim[/color][color=#007700]();[/color][color=#0000bb]char cd2[/color][color=#007700][]=[/color][color=#0000bb]cd[/color][color=#007700].[/color][color=#0000bb]tochararray[/color][color=#007700]();[/color][color=#ff8000]//tim lenh=>fseek;tim file=>fname [/color][color=#007700]for([/color][color=#0000bb]int i[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]<[/color][color=#0000bb]cd[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]();[/color][color=#0000bb]i[/color][color=#007700]++){if([/color][color=#0000bb]cd2[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]]==[/color][color=#dd0000]' '[/color][color=#007700]){[/color][color=#0000bb]fseek[/color][color=#007700]=[/color][color=#0000bb]cd[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]0[/color][color=#007700],[/color][color=#0000bb]i[/color][color=#007700]);[/color][color=#0000bb]fname[/color][color=#007700]=[/color][color=#0000bb]cd[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700](([/color][color=#0000bb]i[/color][color=#007700]+[/color][color=#0000bb]1[/color][color=#007700]),[/color][color=#0000bb]cd[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]());break;}else{[/color][color=#0000bb]fseek[/color][color=#007700]=[/color][color=#0000bb]cd[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]0[/color][color=#007700],[/color][color=#0000bb]cd[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]());}}[/color][color=#ff8000]//system.out.println(fseek);//check//system.out.println(fname);//check//lam the nao de day trang? //chon lenh [/color][color=#007700]switch((string) [/color][color=#0000bb]fseek[/color][color=#007700]){case [/color][color=#dd0000]"
    cd"[/color][color=#007700]:{[/color][color=#0000bb]cd[/color][color=#007700]();break;}case [/color][color=#dd0000]"makefile"[/color][color=#007700]:{[/color][color=#0000bb]makefile[/color][color=#007700]();break;}case [/color][color=#dd0000]"show"[/color][color=#007700]:{[/color][color=#0000bb]show[/color][color=#007700]();break;}}if([/color][color=#0000bb]fseek[/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#dd0000]"stop"[/color][color=#007700])){[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"see you again"[/color][color=#007700]);break;}} [/color][color=#ff8000]//neu nhap duong dan khac/*if(fseek!="cd"||fseek!="makefile"||fseek!="show"){main(null);}*/[/color][color=#007700]} [/color][color=#ff8000]//cac phuong thuc[/color][color=#007700]public static [/color][color=#0000bb]void cd[/color][color=#007700](){[/color][color=#0000bb]file fdisk[/color][color=#007700]=new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]adddisk[/color][color=#007700]);[/color][color=#0000bb]file fdir[/color][color=#007700]=new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]fdisk[/color][color=#007700],[/color][color=#0000bb]fname[/color][color=#007700]);if([/color][color=#0000bb]fdir[/color][color=#007700].[/color][color=#0000bb]isdirectory[/color][color=#007700]()){[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#0000bb]adddisk[/color][color=#007700]+[/color][color=#0000bb]fname[/color][color=#007700]);}else{[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"file not found."[/color][color=#007700]);}}public static [/color][color=#0000bb]void makefile[/color][color=#007700]() [/color][color=#0000bb]throws ioexception[/color][color=#007700]{[/color][color=#0000bb]file fdir[/color][color=#007700]=new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]adddisk[/color][color=#007700]);[/color][color=#0000bb]file ffile[/color][color=#007700]=new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]fdir[/color][color=#007700],[/color][color=#0000bb]fname[/color][color=#007700]);[/color][color=#0000bb]ffile[/color][color=#007700].[/color][color=#0000bb]createnewfile[/color][color=#007700]();[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"successed when create a new file"[/color][color=#007700]);}public static [/color][color=#0000bb]void show[/color][color=#007700]() [/color][color=#0000bb]throws exception[/color][color=#007700]{[/color][color=#0000bb]file fdisk[/color][color=#007700]=new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]adddisk[/color][color=#007700]);[/color][color=#0000bb]file[/color][color=#007700][] list=[/color][color=#0000bb]fdisk[/color][color=#007700].[/color][color=#0000bb]listfiles[/color][color=#007700]();for([/color][color=#0000bb]int i[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]<list.[/color][color=#0000bb]length[/color][color=#007700];[/color][color=#0000bb]i[/color][color=#007700]++){if(list[[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]isdirectory[/color][color=#007700]())[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700](list[[/color][color=#0000bb]i[/color][color=#007700]]);} } }[/color] 

  2. #12
    Ngày tham gia
    Dec 2014
    Bài viết
    0
    <div class="bbcodeblock bbcodequote bbcmspoilerblock">
    <div class="attribution type"><noscript>bai 32 - tao phien ban kieu cmd (move your mouse to reveal the content)</noscript>

    bai 32 - tao phien ban kieu cmd (open)
    bai 32 - tao phien ban kieu cmd (close)

    </div>
    <div class="quotecontent">
    <div class="bbcm_spoiler_noscript"><blockquote>


    Mã nguồn PHP:
    [color=#000000]
    package baitapvenha[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].[/color][color=#0000bb]file[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].[/color][color=#0000bb]ioexception[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]util[/color][color=#007700].[/color][color=#0000bb]scanner[/color][color=#007700];[/color][color=#ff8000]/*** bài tập về nhà: (lần này mình giao bài khó khó chút nhé) tạo 1 chương trình* gần giống cmd trong ms-dos chạy trên màn hình console, chức năng như sau: -* bật chương trình lên mặc định vào ổ e (hoặc ổ nào tùy ý), hiện lên e:\\ (tên* đường đang hiện hành) - gõ "cd tenthumuc" thì màn hình chuyển và hiện lên* e:\\tenthumuc trong đó tenthumuc là tên thư mục tiếp tục muốn truy xuất. - gõ* "makefile tenfile" thì sẽ tạo file trong thư mục hiện hành, trong đó tenfile* là tên file cần tạo. - từ vị trí con trỏ hiện hành, gõ "show" thì hiển thị ra* toàn bộ cấu trúc cây thư mục trong thư mục đó. .... trình bày khá dài dòng* nhỉ, các bạn cứ cố gắng làm càng giống cmd trong ms-dos càng hay, bạn nào làm* xong nhớ share mọi người cùng tham khảo nhé*/ [/color][color=#007700]public class [/color][color=#0000bb]bai32_classfile [/color][color=#007700]{ public static [/color][color=#0000bb]void main[/color][color=#007700]([/color][color=#0000bb]string[/color][color=#007700][] [/color][color=#0000bb]args[/color][color=#007700]) [/color][color=#0000bb]throws ioexception [/color][color=#007700]{ [/color][color=#0000bb]scanner sc [/color][color=#007700]= new [/color][color=#0000bb]scanner[/color][color=#007700]([/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]in[/color][color=#007700]); [/color][color=#0000bb]string strfile[/color][color=#007700]; [/color][color=#0000bb]file checkdisk[/color][color=#007700][]; [/color][color=#0000bb]file f [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"e:\\demofile"[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]getpath[/color][color=#007700]() + [/color][color=#dd0000]">"[/color][color=#007700]); [/color][color=#0000bb]boolean b [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700]; do { [/color][color=#0000bb]strfile [/color][color=#007700]= [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); if ([/color][color=#0000bb]strfile[/color][color=#007700].[/color][color=#0000bb]equalsignorecase[/color][color=#007700]([/color][color=#dd0000]"c:"[/color][color=#007700]) || [/color][color=#0000bb]strfile[/color][color=#007700].[/color][color=#0000bb]equalsignorecase[/color][color=#007700]([/color][color=#dd0000]"d:"[/color][color=#007700]) || [/color][color=#0000bb]strfile[/color][color=#007700].[/color][color=#0000bb]equalsignorecase[/color][color=#007700]([/color][color=#dd0000]"e:"[/color][color=#007700])) { [/color][color=#0000bb]f [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]strfile [/color][color=#007700]+ [/color][color=#dd0000]"\\"[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]getpath[/color][color=#007700]() + [/color][color=#dd0000]">"[/color][color=#007700]); } else if (([/color][color=#0000bb]strfile[/color][color=#007700].[/color][color=#0000bb]tolowercase[/color][color=#007700]()).[/color][color=#0000bb]startswith[/color][color=#007700]([/color][color=#dd0000]"cd"[/color][color=#007700])) { [/color][color=#0000bb]checkdisk [/color][color=#007700]= [/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]listfiles[/color][color=#007700](); [/color][color=#0000bb]boolean check [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700]; for ([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]< [/color][color=#0000bb]checkdisk[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { if ([/color][color=#0000bb]checkdisk[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]isdirectory[/color][color=#007700]() && [/color][color=#0000bb]strfile[/color][color=#007700].[/color][color=#0000bb]comparetoignorecase[/color][color=#007700]([/color][color=#dd0000]"cd " [/color][color=#007700]+ [/color][color=#0000bb]checkdisk[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]getname[/color][color=#007700]()) == [/color][color=#0000bb]0[/color][color=#007700]) { [/color][color=#0000bb]f [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]checkdisk[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]getpath[/color][color=#007700]()); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"" [/color][color=#007700]+ [/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]getpath[/color][color=#007700]() + [/color][color=#dd0000]">"[/color][color=#007700]); [/color][color=#0000bb]check [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700]; break; } else [/color][color=#0000bb]check [/color][color=#007700]= [/color][color=#0000bb]false[/color][color=#007700]; } if (![/color][color=#0000bb]check[/color][color=#007700]) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
    access is fail
    "[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"" [/color][color=#007700]+ [/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]getpath[/color][color=#007700]() + [/color][color=#dd0000]">"[/color][color=#007700]); } } else if ([/color][color=#0000bb]strfile[/color][color=#007700].[/color][color=#0000bb]comparetoignorecase[/color][color=#007700]([/color][color=#dd0000]"show"[/color][color=#007700]) == [/color][color=#0000bb]0[/color][color=#007700]) { [/color][color=#0000bb]file f2 [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]getpath[/color][color=#007700]()); do { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
    " [/color][color=#007700]+ [/color][color=#0000bb]f2[/color][color=#007700].[/color][color=#0000bb]getparent[/color][color=#007700]()); [/color][color=#0000bb]f2 [/color][color=#007700]= [/color][color=#0000bb]f2[/color][color=#007700].[/color][color=#0000bb]getparentfile[/color][color=#007700](); [/color][color=#0000bb]file [/color][color=#007700]list[] = [/color][color=#0000bb]f2[/color][color=#007700].[/color][color=#0000bb]listfiles[/color][color=#007700](); for ([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]< list.[/color][color=#0000bb]length[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
    -->" [/color][color=#007700]+ list[[/color][color=#0000bb]i[/color][color=#007700]]); } } while ([/color][color=#0000bb]f2[/color][color=#007700].[/color][color=#0000bb]getparent[/color][color=#007700]() != [/color][color=#0000bb]null[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
    " [/color][color=#007700]+ [/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]getpath[/color][color=#007700]() + [/color][color=#dd0000]"
    >"[/color][color=#007700]); } else if ([/color][color=#0000bb]strfile[/color][color=#007700].[/color][color=#0000bb]comparetoignorecase[/color][color=#007700]([/color][color=#dd0000]"exit"[/color][color=#007700]) == [/color][color=#0000bb]0[/color][color=#007700]) { [/color][color=#0000bb]b [/color][color=#007700]= [/color][color=#0000bb]false[/color][color=#007700]; } else if ([/color][color=#0000bb]strfile[/color][color=#007700].[/color][color=#0000bb]tolowercase[/color][color=#007700]().[/color][color=#0000bb]startswith[/color][color=#007700]([/color][color=#dd0000]"makefile"[/color][color=#007700])) { [/color][color=#0000bb]string sub [/color][color=#007700]= [/color][color=#0000bb]strfile[/color][color=#007700].[/color][color=#0000bb]replace[/color][color=#007700]([/color][color=#dd0000]"makefile "[/color][color=#007700], [/color][color=#dd0000]""[/color][color=#007700]); [/color][color=#0000bb]f [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]f[/color][color=#007700], [/color][color=#0000bb]sub[/color][color=#007700]); [/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]createnewfile[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"" [/color][color=#007700]+ [/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]getpath[/color][color=#007700]() + [/color][color=#dd0000]">"[/color][color=#007700]); } else { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"'" [/color][color=#007700]+ [/color][color=#0000bb]strfile [/color][color=#007700]+ [/color][color=#dd0000]"' is not recognized as an internall or external command, operable program or batch file."[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]getpath[/color][color=#007700]() + [/color][color=#dd0000]">"[/color][color=#007700]); } } while ([/color][color=#0000bb]b [/color][color=#007700]== [/color][color=#0000bb]true[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"exit application!!!"[/color][color=#007700]); }}[/color] 
    </blockquote></div>
    </div>
    </div>
    /*
    * day la chuong trinh cua minh, moi nguoi check giúp minh nhé.
    * chay ct thi ban doi ten file thu muc bat dau nhe
    * 1. nhap c: ||d: ||e: || "cd <ten o dia>" de truy xuat o dia
    * ==> trong truong hop k co thu muc ban nhap se hien thi "access fail"
    * ==> nhap k dung quy dinh(1) se yeu cau nhap lai
    * 2. nhap 'makefile ' de tao file moi
    * 3. nhap 'show' de xem toan bo cau truc cay thu muc
    * 4. nhap 'exit' neu ban muon thoat chuong trinh
    * ==> tat ca ki tu ban nhap khong phan biet 'hoa' va 'thuong'
    */

  3. #13
    Ngày tham gia
    Dec 2014
    Bài viết
    0
    cho mình hỏi với là nếu tên file lưu utf8 thì làm thế nào để đọc ra mak không bị lỗi hả bạn, màn hình console khi in tên file utf8 lỗi mấy chữ như ư ơ...

Trang 2 của 2 Đầu tiênĐầu tiên 12

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •