Trang 3 của 4 Đầu tiênĐầu tiên 1234 CuốiCuối
Kết quả 21 đến 30 của 33
  1. #21
    Ngày tham gia
    Dec 2014
    Bài viết
    0
    mấy anh ơi cho em hỏi tý. mấy bài trên em thấy dòng: fileinputstream filein = null; nó có nghĩa gì vậy, cám ơn ạ

  2. #22
    Ngày tham gia
    Jul 2015
    Bài viết
    4
    Trích dẫn Gửi bởi zaghinguyen
    ok đã tham khảo 1 số ý kiến chuyên gia và có 1 số nhận xét như sau:
    return trong catch tránh được mấy lỗi ở phía sau:
    vd:nullpointerexception ở hai câu lệnh close cho cái fin va fout ay
    cai return trong catch
    fin = new fileinputstream("e:\\in.mp3");
    fout = new fileoutputstream("e:\\out.mp3");

    nếu exception xảy ra mà ko có return thì code sẽ gặp giá trị num values ở fin.close(); fout.close() phía dưới.
    nếu không dùng return; thì code như thế nào bạn?

  3. #23
    Ngày tham gia
    Feb 2015
    Bài viết
    0
    bài n


    Trích dẫn Gửi bởi phucnguyen6554
    mấy anh ơi cho em hỏi tý. mấy bài trên em thấy dòng: fileinputstream filein = null; nó có nghĩa gì vậy, cám ơn ạ
    bài nào bạn.bạn phải nói rõ vào phần trả lời đó.theo mình đó chỉ là một cách khởi tạo thôi.có thể null hoặc new fileinputstream() cũng tạo ra 1 đối tượng mặc định cũng là null..

  4. #24
    Ngày tham gia
    Apr 2015
    Bài viết
    0
    mới làm cái move với delete
    <div class="bbcodeblock bbcodequote bbcmspoilerblock">
    <div class="attribution type"><noscript>bl (move your mouse to reveal the content)</noscript>

    bl (open)
    bl (close)

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


    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]fileinputstream[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].[/color][color=#0000bb]filenotfoundexception[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].[/color][color=#0000bb]fileoutputstream[/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]javaandroidvn4 [/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 option [/color][color=#007700]= [/color][color=#0000bb]null[/color][color=#007700]; try { [/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=#ff8000]// string k; [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhập lựa chọn---coppy-----delete:"[/color][color=#007700]); [/color][color=#0000bb]option [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]int a [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; if ([/color][color=#0000bb]option[/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#dd0000]"coppy"[/color][color=#007700])) [/color][color=#0000bb]a [/color][color=#007700]= [/color][color=#0000bb]1[/color][color=#007700]; [/color][color=#ff8000]// if(option.equals("move")) // a = 2; [/color][color=#007700]if ([/color][color=#0000bb]option[/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#dd0000]"delete"[/color][color=#007700])) [/color][color=#0000bb]a [/color][color=#007700]= [/color][color=#0000bb]2[/color][color=#007700]; switch ([/color][color=#0000bb]a[/color][color=#007700]) { case [/color][color=#0000bb]1[/color][color=#007700]: [/color][color=#0000bb]string fileinput[/color][color=#007700], [/color][color=#0000bb]fileoutput[/color][color=#007700]; [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"đường dẫn file vào:"[/color][color=#007700]); [/color][color=#0000bb]fileinput [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"đường dẫn file ra"[/color][color=#007700]); [/color][color=#0000bb]fileoutput [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); try { [/color][color=#0000bb]coppy[/color][color=#007700]([/color][color=#0000bb]fileinput[/color][color=#007700], [/color][color=#0000bb]fileoutput[/color][color=#007700]); } 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]"lỗi khi đọc ghi file:" [/color][color=#007700]+ [/color][color=#0000bb]e[/color][color=#007700]); [/color][color=#ff8000]// todo auto-generated catch block // e.printstacktrace(); [/color][color=#007700]} break; case [/color][color=#0000bb]2[/color][color=#007700]: [/color][color=#0000bb]string soufile[/color][color=#007700]; [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"đường dẫn file vào:"[/color][color=#007700]); [/color][color=#0000bb]soufile [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]delete[/color][color=#007700]([/color][color=#0000bb]soufile[/color][color=#007700]); break; case [/color][color=#0000bb]3[/color][color=#007700]: break; } [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700](); } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) { } [/color][color=#ff8000]// input.close(); [/color][color=#007700]} public static [/color][color=#0000bb]void coppy[/color][color=#007700]([/color][color=#0000bb]string fileinput[/color][color=#007700], [/color][color=#0000bb]string fileoutput[/color][color=#007700]) [/color][color=#0000bb]throws ioexception [/color][color=#007700]{ [/color][color=#ff8000]// scanner input1 = new scanner(system.in); // string fileinput; // system.out.println("nhập đường dẫn của file cần coppy:"); // fileinput = input1.nextline(); [/color][color=#0000bb]fileinputstream fin [/color][color=#007700]= [/color][color=#0000bb]null[/color][color=#007700]; try { [/color][color=#0000bb]fin [/color][color=#007700]= new [/color][color=#0000bb]fileinputstream[/color][color=#007700]([/color][color=#0000bb]fileinput[/color][color=#007700]); } catch ([/color][color=#0000bb]filenotfoundexception e[/color][color=#007700]) { [/color][color=#ff8000]// todo auto-generated catch block [/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 file nhập"[/color][color=#007700]); [/color][color=#ff8000]// e.printstacktrace(); [/color][color=#007700]} [/color][color=#ff8000]// string fileoutput; // system.out.println("nhập đường dẫn tên file sau khi coppy:"); // fileoutput = input1.nextline(); [/color][color=#0000bb]fileoutputstream fout [/color][color=#007700]= [/color][color=#0000bb]null[/color][color=#007700]; try { [/color][color=#0000bb]fout [/color][color=#007700]= new [/color][color=#0000bb]fileoutputstream[/color][color=#007700]([/color][color=#0000bb]fileoutput[/color][color=#007700]); } catch ([/color][color=#0000bb]filenotfoundexception e[/color][color=#007700]) { [/color][color=#ff8000]// todo auto-generated catch block [/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 file xuất"[/color][color=#007700]); [/color][color=#ff8000]// e.printstacktrace(); [/color][color=#007700]} [/color][color=#ff8000]// coppy [/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; do { [/color][color=#0000bb]i [/color][color=#007700]= [/color][color=#0000bb]fin[/color][color=#007700].[/color][color=#0000bb]read[/color][color=#007700](); if ([/color][color=#0000bb]i [/color][color=#007700]!= -[/color][color=#0000bb]1[/color][color=#007700]) [/color][color=#0000bb]fout[/color][color=#007700].[/color][color=#0000bb]write[/color][color=#007700]([/color][color=#0000bb]i[/color][color=#007700]); } while ([/color][color=#0000bb]i [/color][color=#007700]!= -[/color][color=#0000bb]1[/color][color=#007700]); [/color][color=#0000bb]fin[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700](); [/color][color=#0000bb]fout[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700](); [/color][color=#ff8000]// input1.close(); [/color][color=#007700]} public static [/color][color=#0000bb]void delete[/color][color=#007700]([/color][color=#0000bb]string soufile[/color][color=#007700]) { try { [/color][color=#0000bb]file file [/color][color=#007700]= [/color][color=#0000bb]null[/color][color=#007700]; [/color][color=#0000bb]file [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]soufile[/color][color=#007700]); [/color][color=#0000bb]scanner in [/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]"bạn có chắc muốn xóa file?(y/n)"[/color][color=#007700]); [/color][color=#0000bb]string lc [/color][color=#007700]= [/color][color=#0000bb]in[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); if ([/color][color=#0000bb]lc[/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#dd0000]"y"[/color][color=#007700])) { [/color][color=#0000bb]file[/color][color=#007700].[/color][color=#0000bb]delete[/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óa thành công"[/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]"lệnh xóa đã bị hủy"[/color][color=#007700]); } [/color][color=#0000bb]in[/color][color=#007700].[/color][color=#0000bb]close[/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]"error:" [/color][color=#007700]+ [/color][color=#0000bb]e[/color][color=#007700]); } }}[/color] 
    </blockquote></div>
    </div>
    </div>

  5. #25
    Ngày tham gia
    Apr 2016
    Bài viết
    0
    Trích dẫn Gửi bởi tiendatii
    theo mình nghĩ biến int i sẽ nhận gía trị trả về là các số 0 1 sau đó lệnh in print sẽ dịch i ra thành dạng char
    mình đã bỏ (char) và kết quả ra toàn là số thôi
    nó đọc theo giá trị ascii của kí tự bạn ạ

  6. #26
    Ngày tham gia
    Oct 2014
    Bài viết
    205
    @tiasangmoi92 và mọi người xem bài này hộ em có cần chỉnh sửa thêm gì nữa không với ạ, em cám ơn
    <div class="bbcodeblock bbcodequote bbcmspoilerblock">
    <div class="attribution type"><noscript>bai 27 (move your mouse to reveal the content)</noscript>

    bai 27 (open)
    bai 27 (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]fileinputstream[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].[/color][color=#0000bb]filenotfoundexception[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].[/color][color=#0000bb]fileoutputstream[/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]/*** biến màn hình console thành màn hình lệnh như sau: - nếu bạn gõ từ "copy",* thì chương trình sẽ hỏi địa chỉ file cần copy, bạn gõ địa chỉ file cần copy* vào, nếu không tồn tại sẽ bắt nhập lại, nếu tồn tại sẽ hỏi địa chỉ file đích,* sau đó chương trình sẽ copy file đó. tương tự với các lệnh "move", "delete" -* gợi ý cách xóa file: thêm 2 dòng lệnh như ví dụ này là bạn có thể xóa được 1* file:*//** hd: nhap file nguon va dich:* nhap lenh muon thuc hien :* ===> menu enter the choose: 1** -- this is coppy --* nhap dia chi file muon coppy: d:\\filename.txt* nhap dia chi file part2 muon ghi ra: d:\\copyfile.txt** -- this is delete --* nhap dia chi file muon delete: e:\\filetest.txt** -- this is move --* nhap dia chi file muon move: d:\\ghilai.txt* nhap vi tri file chuyen den: e:\\**/[/color][color=#007700]public class [/color][color=#0000bb]buoi27 [/color][color=#007700]{ static [/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]); 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]buoi27 test [/color][color=#007700]= new [/color][color=#0000bb]buoi27[/color][color=#007700](); [/color][color=#0000bb]string part1[/color][color=#007700], [/color][color=#0000bb]part2[/color][color=#007700]; [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap lenh muon thuc hien :"[/color][color=#007700]); [/color][color=#0000bb]int lenh [/color][color=#007700]= [/color][color=#0000bb]test[/color][color=#007700].[/color][color=#0000bb]choose[/color][color=#007700](); [/color][color=#0000bb]boolean b [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700]; while ([/color][color=#0000bb]b[/color][color=#007700]) { switch ([/color][color=#0000bb]lenh[/color][color=#007700]) { case [/color][color=#0000bb]1[/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]"
    -- this is coppy --"[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap dia chi file muon coppy: "[/color][color=#007700]); [/color][color=#0000bb]part1 [/color][color=#007700]= [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap dia chi file part2 muon ghi ra: "[/color][color=#007700]); [/color][color=#0000bb]part2 [/color][color=#007700]= [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]test[/color][color=#007700].[/color][color=#0000bb]copyfile[/color][color=#007700]([/color][color=#0000bb]part1[/color][color=#007700], [/color][color=#0000bb]part2[/color][color=#007700]); [/color][color=#0000bb]lenh [/color][color=#007700]= [/color][color=#0000bb]test[/color][color=#007700].[/color][color=#0000bb]choose[/color][color=#007700](); break; case [/color][color=#0000bb]2[/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]"
    -- this is delete --"[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap dia chi file muon delete: "[/color][color=#007700]); [/color][color=#0000bb]part1 [/color][color=#007700]= [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]test[/color][color=#007700].[/color][color=#0000bb]deletefile[/color][color=#007700]([/color][color=#0000bb]part1[/color][color=#007700]); [/color][color=#0000bb]lenh [/color][color=#007700]= [/color][color=#0000bb]test[/color][color=#007700].[/color][color=#0000bb]choose[/color][color=#007700](); break; case [/color][color=#0000bb]3[/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]"
    -- this is move --"[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap dia chi file muon move: "[/color][color=#007700]); [/color][color=#0000bb]part1 [/color][color=#007700]= [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"nhap vi tri file chuyen den: "[/color][color=#007700]); [/color][color=#0000bb]part2 [/color][color=#007700]= [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]test[/color][color=#007700].[/color][color=#0000bb]movefile[/color][color=#007700]([/color][color=#0000bb]part1[/color][color=#007700], [/color][color=#0000bb]part2[/color][color=#007700]); [/color][color=#0000bb]lenh [/color][color=#007700]= [/color][color=#0000bb]test[/color][color=#007700].[/color][color=#0000bb]choose[/color][color=#007700](); break; case [/color][color=#0000bb]4[/color][color=#007700]: [/color][color=#0000bb]b [/color][color=#007700]= [/color][color=#0000bb]false[/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][color=#0000bb]system[/color][color=#007700].exit([/color][color=#0000bb]0[/color][color=#007700]); 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]"the number \"" [/color][color=#007700]+ [/color][color=#0000bb]lenh[/color][color=#007700]+ [/color][color=#dd0000]"\" not valid in system! please try again:"[/color][color=#007700]); [/color][color=#0000bb]lenh [/color][color=#007700]= [/color][color=#0000bb]test[/color][color=#007700].[/color][color=#0000bb]choose[/color][color=#007700](); } } } public [/color][color=#0000bb]void listoperator[/color][color=#007700]() { [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
    ===> menu <==="[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
    1. copy"[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
    2. delete"[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
    3. move"[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
    4. exit"[/color][color=#007700]); [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].print([/color][color=#dd0000]"
    ==> enter the choose: "[/color][color=#007700]); } public [/color][color=#0000bb]int choose[/color][color=#007700]() { [/color][color=#0000bb]int choose [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]listoperator[/color][color=#007700](); try { [/color][color=#0000bb]choose [/color][color=#007700]= [/color][color=#0000bb]integer[/color][color=#007700].[/color][color=#0000bb]parseint[/color][color=#007700]([/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]()); } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) { [/color][color=#ff8000]// todo: handle exception [/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]); } return [/color][color=#0000bb]choose[/color][color=#007700]; } public [/color][color=#0000bb]void copyfile[/color][color=#007700]([/color][color=#0000bb]string part1[/color][color=#007700], [/color][color=#0000bb]string part2[/color][color=#007700]) [/color][color=#0000bb]throws ioexception [/color][color=#007700]{ [/color][color=#0000bb]fileinputstream inputfile [/color][color=#007700]= [/color][color=#0000bb]null[/color][color=#007700]; [/color][color=#0000bb]fileoutputstream outputfile [/color][color=#007700]= [/color][color=#0000bb]null[/color][color=#007700]; try { [/color][color=#0000bb]inputfile [/color][color=#007700]= new [/color][color=#0000bb]fileinputstream[/color][color=#007700]([/color][color=#0000bb]part1[/color][color=#007700]); [/color][color=#0000bb]outputfile [/color][color=#007700]= new [/color][color=#0000bb]fileoutputstream[/color][color=#007700]([/color][color=#0000bb]part2[/color][color=#007700]); } catch ([/color][color=#0000bb]filenotfoundexception 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]"file not found : " [/color][color=#007700]+ [/color][color=#0000bb]e[/color][color=#007700]); return; [/color][color=#ff8000]// todo: handle exception [/color][color=#007700]} catch ([/color][color=#0000bb]arrayindexoutofbound***ception exc[/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]"usage: copyfile from to"[/color][color=#007700]); return; } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) { [/color][color=#ff8000]// todo: handle exception [/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]int i[/color][color=#007700]; try { do { [/color][color=#0000bb]i [/color][color=#007700]= [/color][color=#0000bb]inputfile[/color][color=#007700].[/color][color=#0000bb]read[/color][color=#007700](); if ([/color][color=#0000bb]i [/color][color=#007700]!= -[/color][color=#0000bb]1[/color][color=#007700]) [/color][color=#0000bb]outputfile[/color][color=#007700].[/color][color=#0000bb]write[/color][color=#007700]([/color][color=#0000bb]i[/color][color=#007700]); } while ([/color][color=#0000bb]i [/color][color=#007700]!= -[/color][color=#0000bb]1[/color][color=#007700]); } catch ([/color][color=#0000bb]ioexception e[/color][color=#007700]) { [/color][color=#ff8000]// todo: handle exception [/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]inputfile[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700](); [/color][color=#0000bb]outputfile[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700](); } public [/color][color=#0000bb]void deletefile[/color][color=#007700]([/color][color=#0000bb]string partfile[/color][color=#007700]) { try { [/color][color=#0000bb]file file [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]partfile[/color][color=#007700]); [/color][color=#0000bb]file[/color][color=#007700].[/color][color=#0000bb]delete[/color][color=#007700](); } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) { [/color][color=#ff8000]// todo: handle exception [/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]); return; } } public [/color][color=#0000bb]void movefile[/color][color=#007700]([/color][color=#0000bb]string part1[/color][color=#007700], [/color][color=#0000bb]string part2[/color][color=#007700]) { try { [/color][color=#0000bb]string str[/color][color=#007700][] = [/color][color=#0000bb]part1[/color][color=#007700].[/color][color=#0000bb]split[/color][color=#007700]([/color][color=#dd0000]"\\\\"[/color][color=#007700]); [/color][color=#0000bb]part2 [/color][color=#007700]+=[/color][color=#0000bb]str[/color][color=#007700][[/color][color=#0000bb]str[/color][color=#007700].[/color][color=#0000bb]length[/color][color=#007700]-[/color][color=#0000bb]1[/color][color=#007700]]; [/color][color=#0000bb]copyfile[/color][color=#007700]([/color][color=#0000bb]part1[/color][color=#007700], [/color][color=#0000bb]part2[/color][color=#007700]); [/color][color=#0000bb]deletefile[/color][color=#007700]([/color][color=#0000bb]part1[/color][color=#007700]); } catch ([/color][color=#0000bb]exception e[/color][color=#007700]) { [/color][color=#ff8000]// todo: handle exception [/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] 
    </blockquote></div>
    </div>
    </div>

  7. #27
    Ngày tham gia
    Mar 2014
    Bài viết
    0
    catch có return trả giá trị cho f, nếu không f sẽ không đc khai báo giá trị và k thể đọc hay viết đc. nếu k muốn return thì lúc khai báo cho một giá trị cho f. để null chẳng hạn

  8. #28
    Ngày tham gia
    Apr 2016
    Bài viết
    0
    public class docghifile {
    /**
    * @param args
    */
    public static void main(string[] args) {

    system.out.println("nhập vào chữ cần");
    bufferedreader bf=new bufferedreader(new inputstreamreader(system.in));
    try {
    string ch=bf.readline();
    switch (ch) {
    case "copy":
    system.out.println("nhập địa chỉ file cần copy");
    string diachi;
    file file,file1 = null;
    do
    {
    diachi=bf.readline();
    file=new file("e:\\"+diachi);
    }while(!file.exists());
    if (file.exists())
    {
    system.out.println("nhap vao file đích");
    string dich=bf.readline();
    file1=new file("e:\\"+dich);
    }
    fileinputstream f=new fileinputstream(file);
    fileoutputstream fout=new fileoutputstream(file1);
    int i;
    do
    {
    i=f.read();
    if (i!=-1)
    {
    fout.write(i);
    }
    }while (i!=-1);
    f.close();
    fout.close();
    break;
    case "delete":
    system.out.println("nhap vao dia chi file can delete");
    string diachi1=bf.readline();
    file f1=new file("e:\\"+diachi1);
    f1.delete();
    break;
    case "move":
    system.out.println("nhap vao dia chi file muon di chuyen");
    string diachi2=bf.readline();
    file f2=new file("e:\\"+diachi2);
    f2.renameto(new file("d:\\"+diachi2));
    break;
    default:
    system.out.print("nhập chưa hợp lệ");
    break;
    }

    } catch (ioexception e) {
    e.printstacktrace();
    }
    }
    }

  9. #29
    Ngày tham gia
    Dec 2014
    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 class [/color][color=#0000bb]unit27 [/color][color=#007700]{ private [/color][color=#0000bb]string out[/color][color=#007700]; private [/color][color=#0000bb]string in[/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]); 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]unit27 u [/color][color=#007700]= new [/color][color=#0000bb]unit27[/color][color=#007700](); [/color][color=#0000bb]u[/color][color=#007700].[/color][color=#0000bb]choice[/color][color=#007700](); } public [/color][color=#0000bb]void choice[/color][color=#007700]() [/color][color=#0000bb]throws ioexception [/color][color=#007700]{ [/color][color=#0000bb]int 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]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"1.copy file"[/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]"2.move file"[/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]"3.delete file"[/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]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"moi chon thao tac:"[/color][color=#007700]); [/color][color=#0000bb]i [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); while([/color][color=#0000bb]i [/color][color=#007700]> [/color][color=#0000bb]3 [/color][color=#007700]|| [/color][color=#0000bb]i [/color][color=#007700]< [/color][color=#0000bb]1[/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]"ban da nhap sai, moi nhap lai:"[/color][color=#007700]); [/color][color=#0000bb]i [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextint[/color][color=#007700](); [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); } switch([/color][color=#0000bb]i[/color][color=#007700]) { case [/color][color=#0000bb]1[/color][color=#007700]: [/color][color=#0000bb]copy[/color][color=#007700](); break; case [/color][color=#0000bb]2[/color][color=#007700]: [/color][color=#0000bb]move[/color][color=#007700](); break; case [/color][color=#0000bb]3[/color][color=#007700]: [/color][color=#0000bb]delete[/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]"bye bye"[/color][color=#007700]); break; } } public [/color][color=#0000bb]void copy[/color][color=#007700]() [/color][color=#0000bb]throws ioexception [/color][color=#007700]{ [/color][color=#ff8000]//mở file nguồn //while(true) là vòng lặp vô hạn nên trong thân vòng lặp luôn có lệnh break [/color][color=#0000bb]fileinputstream fin[/color][color=#007700]; [/color][color=#0000bb]fileoutputstream fout[/color][color=#007700]; while([/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]"nhập tên file cần copy:"[/color][color=#007700]); [/color][color=#0000bb]in [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); try { [/color][color=#0000bb]fin [/color][color=#007700]= new [/color][color=#0000bb]fileinputstream[/color][color=#007700]([/color][color=#dd0000]"e:\\" [/color][color=#007700]+ [/color][color=#0000bb]in[/color][color=#007700]); break; } 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]"error:" [/color][color=#007700]+ [/color][color=#0000bb]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]"không thấy file cần tìm, mời nhập lại."[/color][color=#007700]); } } [/color][color=#ff8000]//mở file đích [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"nhập tên file đích:"[/color][color=#007700]); [/color][color=#0000bb]out [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); try { [/color][color=#0000bb]fout [/color][color=#007700]= new [/color][color=#0000bb]fileoutputstream[/color][color=#007700]([/color][color=#dd0000]"e:\\" [/color][color=#007700]+ [/color][color=#0000bb]out[/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]"error:" [/color][color=#007700]+ [/color][color=#0000bb]e[/color][color=#007700]); return; } [/color][color=#ff8000]// copy dữ liệu [/color][color=#0000bb]int i[/color][color=#007700]; try { do { [/color][color=#0000bb]i [/color][color=#007700]= [/color][color=#0000bb]fin[/color][color=#007700].[/color][color=#0000bb]read[/color][color=#007700](); if([/color][color=#0000bb]i [/color][color=#007700]!= -[/color][color=#0000bb]1[/color][color=#007700]) { [/color][color=#0000bb]fout[/color][color=#007700].[/color][color=#0000bb]write[/color][color=#007700]([/color][color=#0000bb]i[/color][color=#007700]); } } while([/color][color=#0000bb]i [/color][color=#007700]!= -[/color][color=#0000bb]1[/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]"error:" [/color][color=#007700]+ [/color][color=#0000bb]e[/color][color=#007700]); return; } [/color][color=#ff8000]//đóng file [/color][color=#0000bb]fout[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700](); [/color][color=#0000bb]fin[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700](); } [/color][color=#ff8000]//muốn move 1 file, có 2 cách //cách 1: sử dụng file.renameto() //cách 2: copy file gốc sang 1 file khác và xóa file gốc, cách này làm sau //dưới đây là cách 1; cách này phải sử dụng lớp file, chắc là lớp cha các lớp // fileinputstream, fileoutputstream [/color][color=#007700]public [/color][color=#0000bb]void move[/color][color=#007700]() { [/color][color=#ff8000]// mở file đích [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"nhap ten file cần di chuyển"[/color][color=#007700]); [/color][color=#0000bb]in [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#ff8000]// nhập tên file và đường dẫn cần chuyển file đến [/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"nhập tên file đích:"[/color][color=#007700]); [/color][color=#0000bb]out [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); try { [/color][color=#0000bb]file file1 [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"e:\\" [/color][color=#007700]+ [/color][color=#0000bb]in[/color][color=#007700]); if([/color][color=#0000bb]file1[/color][color=#007700].[/color][color=#0000bb]renameto[/color][color=#007700](new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"d:\\" [/color][color=#007700]+ [/color][color=#0000bb]out[/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]"move file thành công"[/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]"error:" [/color][color=#007700]+ [/color][color=#0000bb]e[/color][color=#007700]); } } public [/color][color=#0000bb]void delete[/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]"nhap ten file can xoa"[/color][color=#007700]); [/color][color=#0000bb]in [/color][color=#007700]= [/color][color=#0000bb]input[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); try { [/color][color=#0000bb]file f [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"e:\\" [/color][color=#007700]+ [/color][color=#0000bb]in[/color][color=#007700]); [/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]delete[/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]"error:" [/color][color=#007700]+ [/color][color=#0000bb]e[/color][color=#007700]); } } }[/color] 
    </blockquote></div>
    </div>
    </div>

  10. #30
    Ngày tham gia
    Apr 2016
    Bài viết
    0
    mong các bạn đóng góp ý kiến



    Mã nguồn PHP:
    [color=#000000]
    [/color][color=#007700]public class [/color][color=#0000bb]copymovedeletefile [/color][color=#007700]{public static [/color][color=#0000bb]void copyfile[/color][color=#007700]() [/color][color=#0000bb]throws ioexception [/color][color=#007700]{[/color][color=#0000bb]fileinputstream fin [/color][color=#007700]= [/color][color=#0000bb]null[/color][color=#007700];[/color][color=#0000bb]fileoutputstream fout [/color][color=#007700]= [/color][color=#0000bb]null[/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]boolean bol [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700];[/color][color=#0000bb]string address1[/color][color=#007700], [/color][color=#0000bb]address2[/color][color=#007700];try {for ([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]bol [/color][color=#007700]== [/color][color=#0000bb]true[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) {try {[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"address file you want to copy"[/color][color=#007700]);[/color][color=#0000bb]address1 [/color][color=#007700]= [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]();[/color][color=#0000bb]fin [/color][color=#007700]= new [/color][color=#0000bb]fileinputstream[/color][color=#007700]([/color][color=#0000bb]address1[/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]"address file you want to save and new name for file"[/color][color=#007700]);[/color][color=#0000bb]address2 [/color][color=#007700]= [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]();[/color][color=#0000bb]fout [/color][color=#007700]= new [/color][color=#0000bb]fileoutputstream[/color][color=#007700]([/color][color=#0000bb]address2[/color][color=#007700]); [/color][color=#0000bb]bol [/color][color=#007700]= [/color][color=#0000bb]false[/color][color=#007700];} catch ([/color][color=#0000bb]filenotfoundexception e[/color][color=#007700]) {[/color][color=#0000bb]bol [/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]"input file not found"[/color][color=#007700]);}}} catch ([/color][color=#0000bb]arrayindexoutofbound***ception exc[/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]"usage: copyfile from to"[/color][color=#007700]);return;}[/color][color=#0000bb]int j[/color][color=#007700];try {do {[/color][color=#0000bb]j [/color][color=#007700]= [/color][color=#0000bb]fin[/color][color=#007700].[/color][color=#0000bb]read[/color][color=#007700]();if ([/color][color=#0000bb]j [/color][color=#007700]!= -[/color][color=#0000bb]1[/color][color=#007700]) {[/color][color=#0000bb]fout[/color][color=#007700].[/color][color=#0000bb]write[/color][color=#007700]([/color][color=#0000bb]j[/color][color=#007700]);}} while ([/color][color=#0000bb]j [/color][color=#007700]!= -[/color][color=#0000bb]1[/color][color=#007700]);} catch ([/color][color=#0000bb]exception exc[/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 error"[/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]"copy finish "[/color][color=#007700]);[/color][color=#0000bb]fin[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700]();[/color][color=#0000bb]fout[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700]();}public static [/color][color=#0000bb]void delete[/color][color=#007700]() [/color][color=#0000bb]throws ioexception [/color][color=#007700]{[/color][color=#0000bb]file fin [/color][color=#007700]= [/color][color=#0000bb]null[/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]boolean bol [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700];try {for ([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]bol [/color][color=#007700]== [/color][color=#0000bb]true[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) {try {[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"address file you want to delete"[/color][color=#007700]);[/color][color=#0000bb]string address [/color][color=#007700]= [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]();[/color][color=#0000bb]fin [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]address[/color][color=#007700]);if([/color][color=#0000bb]fin[/color][color=#007700].[/color][color=#0000bb]delete[/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]"delete complete"[/color][color=#007700]);[/color][color=#0000bb]bol [/color][color=#007700]= [/color][color=#0000bb]false[/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]"file not found"[/color][color=#007700]);}}} catch ([/color][color=#0000bb]arrayindexoutofbound***ception exc[/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]"usage: copyfile from to"[/color][color=#007700]);return;}[/color][color=#0000bb]fin[/color][color=#007700].[/color][color=#0000bb]exists[/color][color=#007700]();}public static [/color][color=#0000bb]void move[/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]file afile [/color][color=#007700]= [/color][color=#0000bb]null[/color][color=#007700];[/color][color=#0000bb]string address1[/color][color=#007700], [/color][color=#0000bb]address2[/color][color=#007700];[/color][color=#0000bb]boolean bol [/color][color=#007700]= [/color][color=#0000bb]true[/color][color=#007700];try {for ([/color][color=#0000bb]int i [/color][color=#007700]= [/color][color=#0000bb]0[/color][color=#007700]; [/color][color=#0000bb]bol [/color][color=#007700]== [/color][color=#0000bb]true[/color][color=#007700]; [/color][color=#0000bb]i[/color][color=#007700]++) {try {[/color][color=#0000bb]system[/color][color=#007700].[/color][color=#0000bb]out[/color][color=#007700].[/color][color=#0000bb]println[/color][color=#007700]([/color][color=#dd0000]"address file you want to move"[/color][color=#007700]);[/color][color=#0000bb]address1 [/color][color=#007700]= [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]();[/color][color=#0000bb]afile [/color][color=#007700]=new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]address1[/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]"where to move"[/color][color=#007700]);[/color][color=#0000bb]address2 [/color][color=#007700]= [/color][color=#0000bb]sc[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700]();if([/color][color=#0000bb]afile[/color][color=#007700].[/color][color=#0000bb]renameto[/color][color=#007700](new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]address2[/color][color=#007700]+[/color][color=#dd0000]"" [/color][color=#007700]+ [/color][color=#0000bb]afile[/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]"finish"[/color][color=#007700]);[/color][color=#0000bb]bol [/color][color=#007700]= [/color][color=#0000bb]false[/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]"input file not found"[/color][color=#007700]);}}} catch ([/color][color=#0000bb]arrayindexoutofbound***ception exc[/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]"usage: copyfile from to"[/color][color=#007700]);return;}}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 sc2 [/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]"you want :"[/color][color=#007700]);[/color][color=#0000bb]string question [/color][color=#007700]= [/color][color=#0000bb]sc2[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); if ([/color][color=#0000bb]question[/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#dd0000]"copy"[/color][color=#007700])) {[/color][color=#0000bb]copyfile[/color][color=#007700]();} else if ([/color][color=#0000bb]question[/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#dd0000]"move"[/color][color=#007700])) {[/color][color=#0000bb]move[/color][color=#007700]();} else if ([/color][color=#0000bb]question[/color][color=#007700].[/color][color=#0000bb]equals[/color][color=#007700]([/color][color=#dd0000]"delete"[/color][color=#007700])) {[/color][color=#0000bb]delete[/color][color=#007700]();}}}[/color] 

Trang 3 của 4 Đầu tiênĐầu tiên 1234 CuốiCuối

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
  •