Trang 3 của 3 Đầu tiênĐầu tiên 123
Kết quả 21 đến 22 của 22
  1. #21
    Ngày tham gia
    Apr 2015
    Bài viết
    0
    mình nộp bài, có tham khảo chỗ kiểm tra file tồn tại :d
    <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 license header, choose license headers in project properties. * to change this template file, choose tools | templates * and open the template in the editor. */[/color][color=#0000bb]package android[/color][color=#007700].[/color][color=#0000bb]vn[/color][color=#007700]; [/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].[/color][color=#0000bb]datainputstream[/color][color=#007700];[/color][color=#0000bb]import java[/color][color=#007700].[/color][color=#0000bb]io[/color][color=#007700].[/color][color=#0000bb]dataoutputstream[/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=#ff8000]/** * * @author xtruo_000 */[/color][color=#007700]public class [/color][color=#0000bb]bai28 [/color][color=#007700]{ [/color][color=#ff8000]/* tạo đối 1 tượng sinhvien gồm các thuộc tính: tên, năm sinh, điểm trung bình. ghi các thuộc tính này vào file theo kiểu nhị phân. đọc file in thông tin ra ngoài. nếu chạy lại chương trình mà file đã tồn tại thì không tạo đối tượng mới nữa mà in luôn ra thông tin đối tượng đó được đọc từ file! */ // kiểu float khi khởi tạo giá trị phải có chữ f đằng sau [/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]sinhvien sv [/color][color=#007700]= new [/color][color=#0000bb]sinhvien[/color][color=#007700]([/color][color=#dd0000]"xmars"[/color][color=#007700], [/color][color=#0000bb]1990[/color][color=#007700], [/color][color=#0000bb]4.0f[/color][color=#007700]); [/color][color=#0000bb]dataoutputstream dataout[/color][color=#007700]; [/color][color=#0000bb]datainputstream datain[/color][color=#007700]; [/color][color=#ff8000]// contructor: dataoutputstream(outputstream outputstream)// outputstream: là luồng xuất dữ liệu. để ghi dữ liệu ra file thì đối tượng // outputstream có thể là fileoutputstream. // tạo ra luồng dataoutputstream để ghi dữ liệu nhị phân [/color][color=#0000bb]file f [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#dd0000]"e:\\dataout.dat"[/color][color=#007700]); [/color][color=#ff8000]// kiểm tra file có tồn tại hay ko, nếu có rồi thì chuyển luôn sang phần đọc file [/color][color=#007700]if (![/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]exists[/color][color=#007700]()) { try { [/color][color=#0000bb]dataout [/color][color=#007700]= new [/color][color=#0000bb]dataoutputstream[/color][color=#007700](new [/color][color=#0000bb]fileoutputstream[/color][color=#007700]([/color][color=#dd0000]"e:\\dataout.dat"[/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]"cannot open file"[/color][color=#007700]); return; } [/color][color=#ff8000]// bắt đầu ghi dữ liệu nhị phân [/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]"lan luot ghi cac gia tri sau vao file dataout.dat"[/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]"name: " [/color][color=#007700]+ [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]getname[/color][color=#007700]()); [/color][color=#ff8000]// writeutf là ghi xuống luồng 1 giá trị string bằng dữ liệu nhị phân [/color][color=#0000bb]dataout[/color][color=#007700].[/color][color=#0000bb]writeutf[/color][color=#007700]([/color][color=#0000bb]sv[/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]"birthday: " [/color][color=#007700]+ [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]getbirthday[/color][color=#007700]()); [/color][color=#0000bb]dataout[/color][color=#007700].[/color][color=#0000bb]writeint[/color][color=#007700]([/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]getbirthday[/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]"point: " [/color][color=#007700]+ [/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]getpoint[/color][color=#007700]()); [/color][color=#0000bb]dataout[/color][color=#007700].[/color][color=#0000bb]writefloat[/color][color=#007700]([/color][color=#0000bb]sv[/color][color=#007700].[/color][color=#0000bb]getpoint[/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]"write error"[/color][color=#007700]); } [/color][color=#0000bb]dataout[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700](); } [/color][color=#ff8000]//tạo ra luồng datainputstream để đọc dữ liệu nhị phân [/color][color=#007700]try { [/color][color=#ff8000]// đọc dữ liệu từ file mới được tạo ở trên [/color][color=#0000bb]datain [/color][color=#007700]= new [/color][color=#0000bb]datainputstream[/color][color=#007700](new [/color][color=#0000bb]fileinputstream[/color][color=#007700]([/color][color=#dd0000]"e:\\dataout.dat"[/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]"cannot found file"[/color][color=#007700]); return; } [/color][color=#ff8000]// bắt đầu đọc dữ liệu nhị phân [/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]"hien thi cac gia tri doc duoc tu 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]"name: " [/color][color=#007700]+ [/color][color=#0000bb]datain[/color][color=#007700].[/color][color=#0000bb]readutf[/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]"birthday: " [/color][color=#007700]+ [/color][color=#0000bb]datain[/color][color=#007700].[/color][color=#0000bb]readint[/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]"point: " [/color][color=#007700]+ [/color][color=#0000bb]datain[/color][color=#007700].[/color][color=#0000bb]readfloat[/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]"read error"[/color][color=#007700]); } [/color][color=#0000bb]datain[/color][color=#007700].[/color][color=#0000bb]close[/color][color=#007700](); }} class [/color][color=#0000bb]sinhvien [/color][color=#007700]{ private [/color][color=#0000bb]string name[/color][color=#007700]; private [/color][color=#0000bb]int birthday[/color][color=#007700]; private [/color][color=#0000bb]float point[/color][color=#007700]; public [/color][color=#0000bb]sinhvien[/color][color=#007700]([/color][color=#0000bb]string name[/color][color=#007700], [/color][color=#0000bb]int birthday[/color][color=#007700], [/color][color=#0000bb]float point[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]name [/color][color=#007700]= [/color][color=#0000bb]name[/color][color=#007700]; [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]birthday [/color][color=#007700]= [/color][color=#0000bb]birthday[/color][color=#007700]; [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]point [/color][color=#007700]= [/color][color=#0000bb]point[/color][color=#007700]; } public [/color][color=#0000bb]string getname[/color][color=#007700]() { return [/color][color=#0000bb]name[/color][color=#007700]; } public [/color][color=#0000bb]void setname[/color][color=#007700]([/color][color=#0000bb]string name[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]name [/color][color=#007700]= [/color][color=#0000bb]name[/color][color=#007700]; } public [/color][color=#0000bb]int getbirthday[/color][color=#007700]() { return [/color][color=#0000bb]birthday[/color][color=#007700]; } public [/color][color=#0000bb]void setbirthday[/color][color=#007700]([/color][color=#0000bb]int birthday[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]birthday [/color][color=#007700]= [/color][color=#0000bb]birthday[/color][color=#007700]; } public [/color][color=#0000bb]float getpoint[/color][color=#007700]() { return [/color][color=#0000bb]point[/color][color=#007700]; } public [/color][color=#0000bb]void setpoint[/color][color=#007700]([/color][color=#0000bb]float point[/color][color=#007700]) { [/color][color=#0000bb]this[/color][color=#007700].[/color][color=#0000bb]point [/color][color=#007700]= [/color][color=#0000bb]point[/color][color=#007700]; }}[/color] 
    </blockquote></div>
    </div>
    </div>

  2. #22
    Ngày tham gia
    Feb 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=#ff8000]/* * to change this license header, choose license headers in project properties. * to change this template file, choose tools | templates * and open the template in the editor. */[/color][color=#0000bb]package bai27[/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]fileoutputstream[/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]ioexception[/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]util[/color][color=#007700].[/color][color=#0000bb]scanner[/color][color=#007700];[/color][color=#ff8000]/** * * @author tran */[/color][color=#007700]public class [/color][color=#0000bb]bai27copymove [/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 nhap [/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].print([/color][color=#dd0000]"command copy,move,delete:"[/color][color=#007700]); [/color][color=#0000bb]string a [/color][color=#007700]= [/color][color=#0000bb]nhap[/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]"source:"[/color][color=#007700]); [/color][color=#0000bb]string source [/color][color=#007700]= [/color][color=#0000bb]nhap[/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]"target:"[/color][color=#007700]); [/color][color=#0000bb]string target [/color][color=#007700]= [/color][color=#0000bb]nhap[/color][color=#007700].[/color][color=#0000bb]nextline[/color][color=#007700](); [/color][color=#0000bb]fileinputstream fin[/color][color=#007700]; [/color][color=#ff8000]//đọc file [/color][color=#007700]try{ [/color][color=#0000bb]fin [/color][color=#007700]= new [/color][color=#0000bb]fileinputstream[/color][color=#007700]([/color][color=#0000bb]source[/color][color=#007700]); }catch([/color][color=#0000bb]ioexception 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]"inputfile not found"[/color][color=#007700]); return ; } [/color][color=#0000bb]fileoutputstream fout[/color][color=#007700]; [/color][color=#ff8000]//ghi file; [/color][color=#007700]try{ [/color][color=#0000bb]fout [/color][color=#007700]= new [/color][color=#0000bb]fileoutputstream[/color][color=#007700]([/color][color=#0000bb]target[/color][color=#007700]); }catch([/color][color=#0000bb]ioexception 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]"error opening output file"[/color][color=#007700]); return ; }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 : copy to"[/color][color=#007700]); return ; } [/color][color=#ff8000]//xóa [/color][color=#0000bb]file f[/color][color=#007700]; [/color][color=#0000bb]f [/color][color=#007700]= new [/color][color=#0000bb]file[/color][color=#007700]([/color][color=#0000bb]source[/color][color=#007700]); switch ([/color][color=#0000bb]a[/color][color=#007700]){ case [/color][color=#dd0000]"copy"[/color][color=#007700]: [/color][color=#ff8000]//copy [/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]ioexception 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]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](); break; case [/color][color=#dd0000]"move"[/color][color=#007700]: [/color][color=#ff8000]//move [/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]ioexception 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]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=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]delete[/color][color=#007700](); break; case [/color][color=#dd0000]"delete"[/color][color=#007700]: [/color][color=#0000bb]f[/color][color=#007700].[/color][color=#0000bb]delete[/color][color=#007700](); break; } }}[/color] 
    </blockquote></div>
    </div>
    </div>

Trang 3 của 3 Đầu tiênĐầu tiên 123

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
  •