-
08-21-2013, 07:00 AM #1Junior Member
- Ngày tham gia
- Jul 2015
- Bài viết
- 2
Bài 32: Tìm hiểu về lớp File trong Java
/* bài viết thuộc loạt bài hướng dẫn trong "khóa học lập trình java miễn phí"- lớp file thường được dùng để lấy các thông tin về tập tin cũng như thư mục.- hình ảnh ở trên chắc chắn các bạn thấy rất quen thuộc, đó là quá trình 1 phần mềm duyệt thư mục và chờ người dùng tìm, chọn mở 1 file hoặc thư mục nào đó.
trên diễn đàn android.vn, bạn có thể vào đây đọc
để hiểu hơn về khóa học và tham gia ngay cùng mọi người */
android.vn/attachments/untitled-png.22672/" border="0" alt="" />
- kiến thức ở mục này sẽ giúp các bạn hiểu bản chất các câu lệnh có thể làm được điều này, tuy nhiên nếu bạn chưa biết về lập trình giao diện trong java thì chưa thể làm được, ở loạt bài viết về lập trình giao diện trong java mình sẽ nhắc lại và cùng mọi người làm 1 chương trình
có thể duyệt được file, thư mục tương tự như hình ảnh trên!
**chúng ta bắt đầu vào tìm hiểu về lớp file:
1, tạo đối tượng file từ đường dẫn tuyệt đối
public file(string pathname)
ví dụ:
Mã nguồn PHP:[color=#000000]
[/color][color=#ff8000]//tạo trước thư mục "demo" trong ổ e, nếu không chương trình sẽ lỗi[/color][color=#0000bb]file f [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"e:\\demo\\androidvn.txt"[/color][color=#007700]);[/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]createnewfile[/color][color=#007700]();[/color]
Mã nguồn PHP:[color=#000000]
[/color][color=#ff8000]//tạo trước thư mục "demo" trong ổ e, nếu không chương trình sẽ lỗi[/color][color=#0000bb]file f [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"e:\\demo"[/color][color=#007700],[/color][color=#dd0000]"androidvn2.txt"[/color][color=#007700]);[/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]createnewfile[/color][color=#007700]();[/color]
public file(file parent, string child)
ví dụ:
Mã nguồn PHP:[color=#000000]
file dir [/color][color=#007700]= new [/color][color=#0000bb]file [/color][color=#007700]([/color][color=#dd0000]"e:\\demo"[/color][color=#007700]);[/color][color=#0000bb]file f [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]dir[/color][color=#007700],[/color][color=#dd0000]"androidvn3.txt"[/color][color=#007700]);[/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]createnewfile[/color][color=#007700]();[/color]
ví dụ:
Mã nguồn PHP:[color=#000000]
file f [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"e:\\demo2"[/color][color=#007700]);[/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]mkdir[/color][color=#007700]();[/color]
6, lấy danh sách tên các tập tin và thư mục con của đối tượng:
ta sử dụng:
- public string[] list()
file đang xét và trả về trong một mảng.
ví dụ:
Mã nguồn PHP:[color=#000000]
package javaandroidvn[/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]; public class [/color][color=#0000bb]javaandroidvn [/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=#ff8000]//tạo trước thư mục "demo" trong ổ e, tạo 1 vài file và thư mục trong đó [/color][color=#0000bb]file dir [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"e:\\demo"[/color][color=#007700]); [/color][color=#0000bb]file[/color][color=#007700][] [/color][color=#0000bb]listfile [/color][color=#007700]= [/color][color=#0000bb]dir[/color][color=#007700].[/color][color=#0000bb]listfiles[/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]"danh sách file trong thư mục e:\\demo là: "[/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]listfile[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { if ([/color][color=#0000bb]listfile[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]isfile[/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]listfile[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]getname[/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]"danh sách thưc mục trong thư mục e:\\demo là: "[/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]listfile[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { if ([/color][color=#0000bb]listfile[/color][color=#007700][[/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]([/color][color=#0000bb]listfile[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]getname[/color][color=#007700]()); } } }}[/color]
tham khảo thêm 3 video của anh việt bên blog studyandsharebài tập về nhà::d
(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é :d
(chú ý: các bạn nên tự giác làm bài tập, hoàn thiện rồi đăng lên, các bài bạn đã làm, nên để code trong thẻ code - chọn thẻ php cho rõ ràng và để ẩn code trong thẻ ẩn spoiler, để khi click vào mới hiện code lên , trước khi thử sức tự làm, bạn không nên nhìn code của các bạn khác đã đăng nhé)
my facebook: https://www.facebook.com/tiasangmoi
bài viết đăng lên diễn đàn khác vui lòng ghi rõ nguồn: android.vn
-
09-22-2013, 07:00 AM #2Junior Member
- Ngày tham gia
- Apr 2016
- Bài viết
- 0
đã chạy được <div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>
show spoiler
hide spoiler
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
[/color][color=#ff8000]/** to change this template, choose tools | templates* and open the template in the editor.*/[/color][color=#0000bb]package javabasic[/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]filereader[/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]; [/color][color=#ff8000]/**** @author ha*/[/color][color=#007700]public class [/color][color=#0000bb]cmd [/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]){ try { [/color][color=#0000bb]string s[/color][color=#007700]; [/color][color=#0000bb]bufferedreader bf [/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]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"bạn đang ở trình điều khiển cmd ổ đĩa e!
nếu bạn muốn thoát, hãy nhập 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]"bạn đang ở e:\\"[/color][color=#007700]); [/color][color=#0000bb]string pathname [/color][color=#007700]= [/color][color=#dd0000]"e:"[/color][color=#007700]; [/color][color=#0000bb]string temp[/color][color=#007700]; do { [/color][color=#0000bb]s [/color][color=#007700]= [/color][color=#0000bb]bf[/color][color=#007700].[/color][color=#0000bb]readline[/color][color=#007700](); if ([/color][color=#0000bb]s[/color][color=#007700].[/color][color=#0000bb]startswith[/color][color=#007700]([/color][color=#dd0000]"cd"[/color][color=#007700])){ [/color][color=#0000bb]temp [/color][color=#007700]= [/color][color=#0000bb]s[/color][color=#007700].[/color][color=#0000bb]trim[/color][color=#007700]().[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]3[/color][color=#007700]); [/color][color=#0000bb]move[/color][color=#007700]([/color][color=#0000bb]pathname[/color][color=#007700],[/color][color=#0000bb]temp[/color][color=#007700]); [/color][color=#0000bb]pathname [/color][color=#007700]= [/color][color=#0000bb]pathname [/color][color=#007700]+ [/color][color=#dd0000]"\\" [/color][color=#007700]+ [/color][color=#0000bb]temp[/color][color=#007700]; } else if ([/color][color=#0000bb]s[/color][color=#007700].[/color][color=#0000bb]startswith[/color][color=#007700]([/color][color=#dd0000]"makefile"[/color][color=#007700])){ [/color][color=#0000bb]temp [/color][color=#007700]= [/color][color=#0000bb]s[/color][color=#007700].[/color][color=#0000bb]trim[/color][color=#007700]().[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]9[/color][color=#007700]); [/color][color=#0000bb]createfile[/color][color=#007700]([/color][color=#0000bb]pathname[/color][color=#007700], [/color][color=#0000bb]temp[/color][color=#007700]); } else if ([/color][color=#0000bb]s[/color][color=#007700].[/color][color=#0000bb]startswith[/color][color=#007700]([/color][color=#dd0000]"show"[/color][color=#007700])){ [/color][color=#0000bb]show[/color][color=#007700]([/color][color=#0000bb]pathname[/color][color=#007700]); } } while (![/color][color=#0000bb]s[/color][color=#007700].[/color][color=#0000bb]equalsignorecase[/color][color=#007700]([/color][color=#dd0000]"stop"[/color][color=#007700])); } catch ([/color][color=#0000bb]exception ex[/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]"có lỗi xảy ra: " [/color][color=#007700]+ [/color][color=#0000bb]ex[/color][color=#007700]); } } public static [/color][color=#0000bb]void createfile[/color][color=#007700]([/color][color=#0000bb]string pathname[/color][color=#007700], [/color][color=#0000bb]string filename[/color][color=#007700]){ try { [/color][color=#0000bb]file file [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]pathname[/color][color=#007700], [/color][color=#0000bb]filename[/color][color=#007700]); [/color][color=#0000bb]file[/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]"thông báo: file " [/color][color=#007700]+ [/color][color=#0000bb]file[/color][color=#007700].[/color][color=#0000bb]getname[/color][color=#007700]() + [/color][color=#dd0000]" đã được tạo thành công!"[/color][color=#007700]); } catch ([/color][color=#0000bb]exception ex[/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]"đã xảy ra lỗi khi tạo!"[/color][color=#007700]); } } public static [/color][color=#0000bb]void move[/color][color=#007700]([/color][color=#0000bb]string pathname[/color][color=#007700], [/color][color=#0000bb]string dirname[/color][color=#007700]){ try { [/color][color=#0000bb]string s [/color][color=#007700]= [/color][color=#dd0000]""[/color][color=#007700]; [/color][color=#0000bb]pathname [/color][color=#007700]= [/color][color=#0000bb]pathname [/color][color=#007700]+ [/color][color=#dd0000]"\\" [/color][color=#007700]+ [/color][color=#0000bb]dirname[/color][color=#007700]; [/color][color=#0000bb]file file [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]pathname[/color][color=#007700]); if([/color][color=#0000bb]file[/color][color=#007700].[/color][color=#0000bb]isfile[/color][color=#007700]()){ [/color][color=#ff8000]// thuc hien mo file [/color][color=#0000bb]bufferedreader br[/color][color=#007700]= new [/color][color=#0000bb]bufferedreader[/color][color=#007700](new [/color][color=#0000bb]filereader[/color][color=#007700]([/color][color=#0000bb]file[/color][color=#007700])); while (([/color][color=#0000bb]s [/color][color=#007700]= [/color][color=#0000bb]br[/color][color=#007700].[/color][color=#0000bb]readline[/color][color=#007700]()) != [/color][color=#0000bb]null[/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]s[/color][color=#007700]); } } } catch ([/color][color=#0000bb]exception ex[/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]dirname [/color][color=#007700]+ [/color][color=#dd0000]" không tồn tại!"[/color][color=#007700]); } finally { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"bạn đang ở: " [/color][color=#007700]+ [/color][color=#0000bb]pathname[/color][color=#007700]); } } public static [/color][color=#0000bb]void show[/color][color=#007700]([/color][color=#0000bb]string pathname[/color][color=#007700]){ try { [/color][color=#0000bb]file dir [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]pathname[/color][color=#007700]); if ([/color][color=#0000bb]dir[/color][color=#007700].[/color][color=#0000bb]isfile[/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]dir[/color][color=#007700].[/color][color=#0000bb]getname[/color][color=#007700]() + [/color][color=#dd0000]" không phải là thư mục!"[/color][color=#007700]); } else if ([/color][color=#0000bb]dir[/color][color=#007700].[/color][color=#0000bb]isdirectory[/color][color=#007700]()){ [/color][color=#0000bb]file[/color][color=#007700][] [/color][color=#0000bb]listfile [/color][color=#007700]= [/color][color=#0000bb]dir[/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]< [/color][color=#0000bb]listfile[/color][color=#007700].[/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].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]" " [/color][color=#007700]+ [/color][color=#0000bb]i [/color][color=#007700]+ [/color][color=#dd0000]", " [/color][color=#007700]+ [/color][color=#0000bb]listfile[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]getname[/color][color=#007700]()); } } } catch ([/color][color=#0000bb]exception ex[/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]"lỗi khi show file! " [/color][color=#007700]+ [/color][color=#0000bb]ex[/color][color=#007700]); } }}[/color]
</div>
</div>
-
-
10-05-2013, 07:00 AM #4Junior Member
- Ngày tham gia
- May 2015
- Bài viết
- 0
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>
show spoiler
hide spoiler
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã:import java.io.file; import java.io.filenotfoundexception; import java.io.ioexception; import java.util.scanner; public class btbai32 { public static void main(string[]args) throws ioexception{ scanner in=new scanner(system.in); string d="d:\\\\"; system.out.println(d); string s=in.nextline(); string s1,s2,s3; switch(s) { case "cd": { try{ system.out.println("nhap ten thu muc"); s1=in.nextline(); taodirectory(d,s1); system.out.println("nhap file or show thu muc ?"); s3=in.nextline(); switch(s3) { case "makefile": { system.out.println("nhap ten file"); s2=in.nextline(); taofile(s1,s2); break; } case "show": { showdirectory(d+s1); break; } default: system.out.println("cd success"); } }catch(exception exc){ system.out.println("error cd directory"); } break; } case "makefile": { try{ system.out.println("nhap ten thu muc:"); s1=in.nextline(); system.out.println("nhap ten file"); s2=in.nextline(); taofile(s1,s2); }catch(ioexception exc){ system.out.println("error make file"); } break; } case "show": { try{ system.out.println("show thu muc"); system.out.println("ten thu muc:"); s1=in.nextline(); showdirectory(s1); }catch(exception exc){ system.out.println("error show file"); } break; } default: system.out.println("try again"); } } public static void taodirectory(string d,string s) { system.out.println(d+s); } public static void taofile(string s1,string s2) throws ioexception { string d1="d:\\\\"+""+s1+"\\"+s2; file f = new file(d1); f.createnewfile(); system.out.println(d1); } public static void showdirectory(string s) { //tạo trước thư mục "demo" trong ổ d, tạo 1 vài file và thư mục trong đó file dir = new file(s); file[] listfile = dir.listfiles(); system.out.println("danh sách file trong thư mục "+s+" là: "); for (int i = 0; i < listfile.length; i++) { if (listfile[i].isfile()) { system.out.println(listfile[i].getname()); } } system.out.println("danh sách thưc mục trong thư mục "+s+" là: "); for (int i = 0; i < listfile.length; i++) { if (listfile[i].isdirectory()) { system.out.println(listfile[i].getname()); } } } }
</div>
</div>
-
02-10-2014, 07:00 AM #5Junior Member
- Ngày tham gia
- Mar 2015
- Bài viết
- 0
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>
show spoiler
hide spoiler
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
[/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]file f [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"d:\\"[/color][color=#007700]); [/color][color=#0000bb]string command[/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]); do { [/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]string temp[/color][color=#007700][] = [/color][color=#0000bb]br[/color][color=#007700].[/color][color=#0000bb]readline[/color][color=#007700]().[/color][color=#0000bb]split[/color][color=#007700]([/color][color=#dd0000]" "[/color][color=#007700]); [/color][color=#0000bb]command [/color][color=#007700]= [/color][color=#0000bb]temp[/color][color=#007700][[/color][color=#0000bb]0[/color][color=#007700]]; switch ( [/color][color=#0000bb]temp[/color][color=#007700][[/color][color=#0000bb]0[/color][color=#007700]]) { case [/color][color=#dd0000]"cd"[/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]temp[/color][color=#007700][[/color][color=#0000bb]1[/color][color=#007700]]); if ( ![/color][color=#0000bb]f[/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]temp[/color][color=#007700][[/color][color=#0000bb]1[/color][color=#007700]] + [/color][color=#dd0000]" is not a directory!"[/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]getparent[/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]); break; case [/color][color=#dd0000]"makefile"[/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]temp[/color][color=#007700][[/color][color=#0000bb]1[/color][color=#007700]]); [/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]createnewfile[/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]getparent[/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]); break; case [/color][color=#dd0000]"show"[/color][color=#007700]: [/color][color=#0000bb]file[/color][color=#007700][] [/color][color=#0000bb]f2 [/color][color=#007700]= [/color][color=#0000bb]f[/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]< [/color][color=#0000bb]f2[/color][color=#007700].[/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].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#0000bb]f2[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]getname[/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]); break; case [/color][color=#dd0000]"exit"[/color][color=#007700]: break; default: [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"command not valid!"[/color][color=#007700]); } } while ( [/color][color=#0000bb]command[/color][color=#007700].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#dd0000]"exit"[/color][color=#007700]) != [/color][color=#0000bb]0[/color][color=#007700]); }[/color]
</div>
</div>
-
03-06-2014, 07:00 AM #6Junior Member
- Ngày tham gia
- Apr 2015
- Bài viết
- 0
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>
show spoiler
hide spoiler
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
package nhansu[/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]bufferedreader[/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];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].[/color][color=#0000bb]file[/color][color=#007700];public class [/color][color=#0000bb]cmd [/color][color=#007700]{ public [/color][color=#0000bb]void thumuc[/color][color=#007700]()[/color][color=#0000bb]throws ioexception[/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]"microsoft windows [version 6.1.7601]"[/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]"copyright (c) 2009 microsoft corporation. all right reserved."[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"c:\users\administrator>"[/color][color=#007700]); [/color][color=#0000bb]int k[/color][color=#007700]=[/color][color=#0000bb]0[/color][color=#007700]; while([/color][color=#0000bb]k[/color][color=#007700]==[/color][color=#0000bb]0[/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]string st[/color][color=#007700]=[/color][color=#0000bb]br[/color][color=#007700].[/color][color=#0000bb]readline[/color][color=#007700](); [/color][color=#0000bb]string st4[/color][color=#007700]=[/color][color=#0000bb]st[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]0[/color][color=#007700],[/color][color=#0000bb]8[/color][color=#007700]); if([/color][color=#0000bb]st4[/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#dd0000]"makefile"[/color][color=#007700])){ [/color][color=#0000bb]string st5[/color][color=#007700]=[/color][color=#0000bb]st[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]9[/color][color=#007700]); [/color][color=#0000bb]k[/color][color=#007700]=[/color][color=#0000bb]1[/color][color=#007700]; [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"thu muc luu file:"[/color][color=#007700]); [/color][color=#0000bb]string st6[/color][color=#007700]=[/color][color=#0000bb]br[/color][color=#007700].[/color][color=#0000bb]readline[/color][color=#007700](); [/color][color=#0000bb]st5[/color][color=#007700]=[/color][color=#0000bb]st6[/color][color=#007700]+[/color][color=#dd0000]"\\"[/color][color=#007700]+[/color][color=#dd0000]"\\"[/color][color=#007700]+[/color][color=#0000bb]st5[/color][color=#007700]; [/color][color=#0000bb]file f[/color][color=#007700]=new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]st5[/color][color=#007700]); [/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]createnewfile[/color][color=#007700](); [/color][color=#0000bb]string st7[/color][color=#007700]=[/color][color=#0000bb]br[/color][color=#007700].[/color][color=#0000bb]readline[/color][color=#007700](); if([/color][color=#0000bb]st7[/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#dd0000]"show"[/color][color=#007700])){ [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"thu muc:"[/color][color=#007700]); [/color][color=#0000bb]string st8[/color][color=#007700]=[/color][color=#0000bb]br[/color][color=#007700].[/color][color=#0000bb]readline[/color][color=#007700](); [/color][color=#0000bb]file f2[/color][color=#007700]=new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]st8[/color][color=#007700]); [/color][color=#0000bb]file [/color][color=#007700][][/color][color=#0000bb]mang[/color][color=#007700]=[/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]<[/color][color=#0000bb]mang[/color][color=#007700].[/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].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#0000bb]mang[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]getname[/color][color=#007700]()); } break; } [/color][color=#0000bb]string st2[/color][color=#007700]=[/color][color=#0000bb]st[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]3[/color][color=#007700]); [/color][color=#0000bb]string st3[/color][color=#007700]=[/color][color=#0000bb]st2[/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]st3[/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]cmd a[/color][color=#007700]=new [/color][color=#0000bb]cmd[/color][color=#007700](); [/color][color=#0000bb]a[/color][color=#007700].[/color][color=#0000bb]thumuc[/color][color=#007700](); }}[/color]
</div>
</div>
-
04-10-2014, 07:00 AM #7Junior Member
- Ngày tham gia
- Apr 2016
- Bài viết
- 0
code hơi dài, nhưng khắc phục được khi gõ trống không cd, cd[space] và trả về e:\\
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>spoiler (move your mouse to the spoiler area to reveal the content)</noscript>
show spoiler
hide spoiler
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
package javabasic[/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=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].*; [/color][color=#ff8000]/**** @author zhenyuan0502*/[/color][color=#007700]public class [/color][color=#0000bb]thuchanh_file [/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]string locate[/color][color=#007700], [/color][color=#0000bb]locate_c[/color][color=#007700], [/color][color=#0000bb]locate_c_c[/color][color=#007700]; [/color][color=#0000bb]int i[/color][color=#007700]; [/color][color=#0000bb]int k [/color][color=#007700]= [/color][color=#0000bb]1[/color][color=#007700]; [/color][color=#0000bb]scanner input [/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]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"press [ stop ] to stop process"[/color][color=#007700]); [/color][color=#0000bb]label[/color][color=#007700]: do { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"e:\\\\"[/color][color=#007700]); [/color][color=#0000bb]locate [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); if ([/color][color=#0000bb]locate[/color][color=#007700].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#dd0000]"stop"[/color][color=#007700]) == [/color][color=#0000bb]0[/color][color=#007700]) { break; } if ([/color][color=#0000bb]locate[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]() < [/color][color=#0000bb]4[/color][color=#007700]) { } else { if (([/color][color=#0000bb]locate[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]0[/color][color=#007700], [/color][color=#0000bb]3[/color][color=#007700]).[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#dd0000]"cd "[/color][color=#007700]) == [/color][color=#0000bb]0[/color][color=#007700]) && ([/color][color=#0000bb]locate[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]3[/color][color=#007700]) != [/color][color=#0000bb]null[/color][color=#007700]) ) { try { [/color][color=#0000bb]file f [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]locate[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]3[/color][color=#007700])); [/color][color=#ff8000]//4 [/color][color=#0000bb]file dir [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"e:\\\\"[/color][color=#007700]); [/color][color=#0000bb]file[/color][color=#007700][] [/color][color=#0000bb]listf [/color][color=#007700]= [/color][color=#0000bb]dir[/color][color=#007700].[/color][color=#0000bb]listfiles[/color][color=#007700](); for ([/color][color=#0000bb]i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]< [/color][color=#0000bb]listf[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { if ((([/color][color=#0000bb]listf[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]getname[/color][color=#007700]()).[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#0000bb]locate[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]3[/color][color=#007700])) == [/color][color=#0000bb]0[/color][color=#007700]) && [/color][color=#0000bb]listf[/color][color=#007700][[/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]([/color][color=#dd0000]"e:\\\\" [/color][color=#007700]+ [/color][color=#0000bb]locate[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]3[/color][color=#007700]) + [/color][color=#dd0000]"\\"[/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]"you want to create a file? press [ makefile file_name ] to create or [ stop ] to stop process"[/color][color=#007700]); [/color][color=#0000bb]locate_c [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); if ([/color][color=#0000bb]locate_c[/color][color=#007700].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#dd0000]"stop"[/color][color=#007700]) == [/color][color=#0000bb]0[/color][color=#007700]) { [/color][color=#0000bb]k [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; return; } if (([/color][color=#0000bb]locate_c[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]0[/color][color=#007700], [/color][color=#0000bb]9[/color][color=#007700]).[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#dd0000]"makefile "[/color][color=#007700]) == [/color][color=#0000bb]0[/color][color=#007700]) && ([/color][color=#0000bb]locate_c[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]9[/color][color=#007700]) != [/color][color=#0000bb]null[/color][color=#007700])) { try { [/color][color=#0000bb]file fc [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"e:\\\\" [/color][color=#007700]+ [/color][color=#0000bb]locate[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]3[/color][color=#007700]) + [/color][color=#dd0000]"\\" [/color][color=#007700]+ [/color][color=#0000bb]locate_c[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]9[/color][color=#007700]) + [/color][color=#dd0000]"\\"[/color][color=#007700]); [/color][color=#0000bb]fc[/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]"create file success"[/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]"you want to show subfolder in this folder? [show/stop] "[/color][color=#007700]); [/color][color=#0000bb]locate_c_c [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); if ([/color][color=#0000bb]locate_c_c[/color][color=#007700].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#dd0000]"stop"[/color][color=#007700]) == [/color][color=#0000bb]0[/color][color=#007700]) { [/color][color=#0000bb]k [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; return; } if ([/color][color=#0000bb]locate_c_c[/color][color=#007700].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#dd0000]"show"[/color][color=#007700]) == [/color][color=#0000bb]0[/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]"e:\\\\" [/color][color=#007700]+ [/color][color=#0000bb]locate[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]3[/color][color=#007700]) + [/color][color=#dd0000]"\\"[/color][color=#007700]); [/color][color=#0000bb]file dir_c [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"e:\\\\" [/color][color=#007700]+ [/color][color=#0000bb]locate[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]3[/color][color=#007700]) + [/color][color=#dd0000]"\\"[/color][color=#007700]); [/color][color=#0000bb]file[/color][color=#007700][] [/color][color=#0000bb]listf_c [/color][color=#007700]= [/color][color=#0000bb]dir_c[/color][color=#007700].[/color][color=#0000bb]listfiles[/color][color=#007700](); for ([/color][color=#0000bb]i [/color][color=#007700]= [/color][color=#0000bb]1[/color][color=#007700]; [/color][color=#0000bb]i [/color][color=#007700]< [/color][color=#0000bb]listf_c[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { if ([/color][color=#0000bb]listf_c[/color][color=#007700][[/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]([/color][color=#dd0000]"e:\\\\" [/color][color=#007700]+ [/color][color=#0000bb]locate[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]3[/color][color=#007700]) + [/color][color=#dd0000]"\\" [/color][color=#007700]+ [/color][color=#0000bb]listf_c[/color][color=#007700][[/color][color=#0000bb]i[/color][color=#007700]].[/color][color=#0000bb]getname[/color][color=#007700]()); } } [/color][color=#0000bb]k [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; return; } [/color][color=#0000bb]k [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; return; } catch ([/color][color=#0000bb]ioexception e[/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]"error: " [/color][color=#007700]+ [/color][color=#0000bb]e[/color][color=#007700]); } } [/color][color=#0000bb]k [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; return; } } if ([/color][color=#0000bb]k [/color][color=#007700]!= [/color][color=#0000bb]0[/color][color=#007700]) { continue [/color][color=#0000bb]label[/color][color=#007700]; } } catch ([/color][color=#0000bb]exception e[/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]"folder not found"[/color][color=#007700]); throw [/color][color=#0000bb]e[/color][color=#007700]; } } } } while ([/color][color=#0000bb]true[/color][color=#007700]); }}[/color]
</div>
</div>
-
07-18-2014, 07:00 AM #8Junior Member
- Ngày tham gia
- Nov 2014
- Bài viết
- 0
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>nb (move your mouse to reveal the content)</noscript>
nb (open)
nb (close)
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>
Mã nguồn PHP:[color=#000000]
package java_java[/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]; public class [/color][color=#0000bb]cmd [/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 input [/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 option [/color][color=#007700]= new [/color][color=#0000bb]string[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"d:\\\\"[/color][color=#007700]); [/color][color=#0000bb]option [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); if ([/color][color=#0000bb]option[/color][color=#007700].[/color][color=#0000bb]startswith[/color][color=#007700]([/color][color=#dd0000]"cd"[/color][color=#007700])) { [/color][color=#0000bb]option [/color][color=#007700]= [/color][color=#dd0000]"d:\\\\" [/color][color=#007700]+ [/color][color=#0000bb]option[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]3[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#0000bb]option[/color][color=#007700]); } if ([/color][color=#0000bb]option[/color][color=#007700].[/color][color=#0000bb]startswith[/color][color=#007700]([/color][color=#dd0000]"makefile"[/color][color=#007700])) { [/color][color=#0000bb]string tenfile[/color][color=#007700]; [/color][color=#ff8000]// string d; // system.out.print("d:\\\\"); [/color][color=#0000bb]tenfile [/color][color=#007700]= [/color][color=#0000bb]option[/color][color=#007700].[/color][color=#0000bb]substring[/color][color=#007700]([/color][color=#0000bb]9[/color][color=#007700]); [/color][color=#0000bb]tenfile [/color][color=#007700]= [/color][color=#dd0000]"d:\\\\" [/color][color=#007700]+ [/color][color=#0000bb]tenfile[/color][color=#007700]; [/color][color=#0000bb]file dir [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]tenfile[/color][color=#007700]); [/color][color=#0000bb]dir[/color][color=#007700].[/color][color=#0000bb]createnewfile[/color][color=#007700](); } if ([/color][color=#0000bb]option[/color][color=#007700].[/color][color=#0000bb]compareto[/color][color=#007700]([/color][color=#dd0000]"show"[/color][color=#007700]) == [/color][color=#0000bb]0[/color][color=#007700]) { [/color][color=#0000bb]file dir [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"d:\\"[/color][color=#007700]); [/color][color=#0000bb]file[/color][color=#007700][] [/color][color=#0000bb]listfile [/color][color=#007700]= [/color][color=#0000bb]dir[/color][color=#007700].[/color][color=#0000bb]listfiles[/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]"thu muc:"[/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]listfile[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { if ([/color][color=#0000bb]listfile[/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]listfile[/color][color=#007700].[/color][color=#0000bb]getname[/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]"file:"[/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]listfile[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) { if ([/color][color=#0000bb]listfile[/color][color=#007700].[/color][color=#0000bb]isabsolute[/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]listfile[/color][color=#007700].[/color][color=#0000bb]getname[/color][color=#007700]()); } } } [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700](); } }[/color]
</div>
</div>
-
07-30-2014, 07:00 AM #9Junior Member
- Ngày tham gia
- Apr 2014
- Bài viết
- 2
<div class="bbcodeblock bbcodequote bbcmspoilerblock">
<div class="attribution type"><noscript>[php (move your mouse to reveal the content)</noscript>
[php (open)
[php (close)
</div>
<div class="quotecontent">
<div class="bbcm_spoiler_noscript"><blockquote>package baitap;
import java.io.*;
import java.util.scanner;
public class unit32 {
public void taothumuc(string folder){
try {
file dir = new file(folder);
dir.mkdir();
} catch (exception e) {
system.out.println("k the tao thu muc");
}
}
public static void main(string[] args) throws ioexception {
scanner in=new scanner(system.in);
unit32 un= new unit32();
string a,a1,b1,b,show;
system.out.print("d:\\");
a=in.nextline();
a1="d:\\"+a.substring(3,a.length());
un.taothumuc(a1);
system.out.println(a1);
b=in.nextline();
b1=b.substring(9,b.length());
file f= new file(a1,b1);
f.createnewfile();
show=in.nextline();
if(show.equalsignorecase("show")==true){
system.out.println(f.getpath());
}
}
} [/php]]</blockquote></div>
</div>
</div>
-
08-18-2014, 07:00 AM #10Junior Member
- Ngày tham gia
- Jul 2015
- Bài viết
- 0
cảm ơn rất nhiều !
| dưỡng da
Khi quan tâm đến thẩm mỹ vùng kín. Nhiều chị em hay tìm hiểu: Bác sĩ thẩm mỹ vùng kín giỏi và thẩm mỹ vùng kín ở đâu an toàn Đà Nẵng. Bài viết này sẽ giới thiệu đến các bạn một trong số những bác sĩ...
Làm Đẹp Vùng Kín An Toàn Và Hiệu Quả Với Bác Sĩ Thẩm Mỹ Tại Đà Nẵng