Java FileInputStream finalize()方法與示例

FileInputStream類的finalize()方法 (FileInputStream Class finalize() method)

  • finalize() method is available in java.io package.

    finalize()方法在java.io包中可用。

  • finalize() method is used to assure that close() method of this FileInputStream invokes when there are none references exists or in other words, we can say close() method call after destroying or free all of its references.

    finalize()方法用于確保在不存在任何引用的情況下調用此FileInputStream的close()方法,換句話說,我們可以在銷毀或釋放所有引用之后說close()方法調用。

  • finalize() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    finalize()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • finalize() method may throw an exception at the time of finalizing the stream.

    finalize()方法可能會在最終確定流時拋出異常。

    IOException: This exception may throw while getting any input/output error.

    IOException :在獲取任何輸入/輸出錯誤時,可能引發此異常。

Syntax:

句法:

    protected void finalize();

Parameter(s):

參數:

  • It does not accept any parameter.

    它不接受任何參數。

Return value:

返回值:

The return type of the method is void, it returns nothing.

該方法的返回類型為void ,不返回任何內容。

Example:

例:

// Java program to demonstrate the example 
// of void finalize() method of FileInputStream
import java.io.*;
public class FinalizeOfFIS extends FileInputStream {
public FinalizeOfFIS() throws Exception {
super("D:\\includehelp.txt");
}
public static void main(String[] args) throws IOException {
int val;
try {
// Instantiates FinalizeOfFIS
FinalizeOfFIS fis_stm = new FinalizeOfFIS();
// By using read() method is to read
// a byte from fis_stm
val = fis_stm.read();
// Display corresponding bytes value
byte b = (byte) val;
// Display value of b
System.out.println("fis_stm.read() before finalize(): " + b);
// By using finalize() method is to free
// memory when no more references exists   
fis_stm.finalize();
// when we call read() method after
// finalizing the stream will not result an exception
val = fis_stm.read();
b = (byte) val;
System.out.println("fis_stm.read() after finalize(): " + b);
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
}

Output

輸出量

fis_stm.read() before finalize(): 0
fis_stm.read() after finalize(): 4

翻譯自: https://www.includehelp.com/java/fileinputstream-finalize-method-with-example.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379372.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379372.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379372.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

逆風飛揚,吳仁宏

摘自逆風飛揚,吳仁宏自傳 它是一個從"生而自卑"到"個性飛揚"的故事,當然具有傳奇色彩 中國人幾千年都不是天生的贏家,讓我們努力,為國為家為自己,做贏家! 生存哲學 尼采 痛苦,挫折使生命遷長,使人…

ffmpeg 命令圖片和視頻相互轉換

1當前文件環境: ffmpeg -i test.mp4 -y -f image2 -ss 00:00:02 -vframes 1 -s 640x360 test.jpg ffmpeg -i test.mp4 -y -f image2 -ss 00:00:02 -vframes 1 -s 640x360 test.bmp 使用ffplay test.jpb ffplay test.bmp 都是可以打開的 參數介紹: -y 如…

如何點擊鏈接直接跳轉到app store指定應用下載頁面

轉載自:http://blog.csdn.net/zengconggen/article/details/6789420 NSString *str [NSString stringWithFormat:"http://itunes.apple.com/us/app/id%d", 436957167]; [[UIApplication sharedApplication] openURL:[NSURL urlWithString:str]];其中&…

COLLEGE.sql(復制的時候注意路徑!!!)

USE [master] GO /****** Object: Database [COLLEGE] Script Date: 2019/11/25 星期一 上午 08:57:11 / CREATE DATABASE [COLLEGE] ON PRIMARY ( NAME N’COLLEGE_m’, FILENAME N’F:\COLLEGE\COLLEGE.mdf’ , SIZE 51200KB , MAXSIZE UNLIMITED, FILEGROWTH 10240KB )…

【管理】「本能叛逆」與「理性叛逆」

叛逆是一般人認知的負面名詞,但是,很多人都忽略掉,它卻是人類進步的重要因子。觀察孩童的成長過程,十歲以后都會出現叛逆行為,相當令父母及師長頭痛。然而,叛逆卻是促使孩童突破家庭單一環境養成的認知與觀…

Java Double類parseDouble()方法的示例

Double類parseDouble()方法 (Double class parseDouble() method) parseDouble() method is available in java.lang package. parseDouble()方法在java.lang包中可用。 parseDouble() method is used to return the double value corresponding to the given String or in oth…

ffmpeg命令 拉流

1: 拉流播放:rtmp (ffplay rtmp://server/live/streamName) ffplay -x 480 -y 320 rtmp://58.200.131.2:1935/livetv/cctv1 2: 拉流存儲到文件:rtmp ffmpeg -i rtmp://58.200.131.2:1935/livetv/cctv1 -codec copy cctvrtmp.f…

小心pthread_cond_signal和SetEvent之間的差異

ZZ FROM: http://blog.csdn.net/absurd/article/details/1402433 轉載時請注明出處和作者聯系方式&#xff1a;http://blog.csdn.net/absurd 作者聯系方式&#xff1a;Li XianJing <xianjimli at hotmail dot com> 更新時間&#xff1a;2006-12-19 今天幫同事查一個多線…

eshop.sql(復制的時候注意路徑!!!)

USE [master] GO /****** Object: Database [eshop] Script Date: 2019/11/25 星期一 上午 08:54:14 / CREATE DATABASE [eshop] ON PRIMARY ( NAME N’eshop_dat’, FILENAME N’D:\eshop\eshop_dat.mdf’ , SIZE 10240KB , MAXSIZE 51200KB , FILEGROWTH 5120KB ) LOG O…

doublevalue_Java Double類doubleValue()方法與示例

doublevalueDouble類doubleValue()方法 (Double class doubleValue() method) doubleValue() method is available in java.lang package. doubleValue()方法在java.lang包中可用。 doubleValue() method is used to return the value denoted by this Double object converted…

ffmpeg 命令過濾器裁剪

1 圖片操作&#xff1a; 原圖&#xff1a; 使用ffplay 顯示左半邊 ffplay -i input.png -vf cropiw/2:ih:0:0 可以通過ffmpeg 保存 ffmpeg -i input.png -vf cropiw/2:ih:0:0 out.png 2 視頻操作&#xff1a; 原視頻&#xff1a; 顯示左半邊 ffplay -i cctvhttp.flv -vf …

去除aspx生成的頁面最開始的空行

使用.aspx生成的頁面一般都會有一個或多個空行&#xff0c;當然這些空行不會影響頁面在瀏覽器中的渲染結果&#xff0c;不過在查看源代碼的時候感覺有些別扭&#xff0c;我曾試著去刪除這些空行&#xff0c;但沒有成功&#xff0c;你知道你們有沒有去嘗試。 1 <% Page Langu…

PUBLISH.sql(復制的時候注意路徑!!!)

USE [master] – GO – /****** Object: Database [PUBLISH] Script Date: 2019/11/25 星期一 上午 09:00:04 / – CREATE DATABASE [PUBLISH] ON PRIMARY – ( NAME N’PUBLISH’, FILENAME N’F:\PUBLISH\PUBLISH.mdf’ , SIZE 51200KB , MAXSIZE UNLIMITED, FILEGROWTH …

c ++ 函數的esp指針_在C ++中通過指針訪問成員函數

c 函數的esp指針Create a class along with data member and member functions and then access the member functions by using a pointer in C. 創建一個類以及數據成員和成員函數&#xff0c;然后使用C 中的指針訪問成員函數。 如何通過指針訪問成員函數&#xff1f; (How…

[iphone-cocos2d]分享一段Objective-C可調用的游戲中播放音樂(1)

首先需要引入AudioTool 這個framework 代碼 -(id)initWithPath:(NSString *)path{ UInt32 size, maxPacketSize; char*cookie; inti; if(gThereIsAnActiveTrack) { NSLog("*** WARNING *** GBMusicTrack only plays one track at a time…

匯編語言-010(循環移位ROL,ROR 、進位循環進位RCL,RCR 、有符號數溢出 、雙精度移位SHLD,SHRD、SHL和ADD計算 、位運算應用)

1 &#xff1a;循環移位ROL,ROR,帶進位循環進位RCL,RCR .386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.code main PROC;循環左移mov al,40h ;AL 010000000brol al,1 ;AL 100000000b ,CF 0rol al,1 ;AL 000000001b ,CF 1rol al,1 ;A…

[Z]POJ 計算幾何入門題目推薦[轉PKKJ]

http://www.cnblogs.com/eric-blog/archive/2011/05/31/2064785.html http://hi.baidu.com/novosbirsk/blog/item/723a9727a9ab8804918f9dca.html其實也談不上推薦&#xff0c;只是自己做過的題目而已&#xff0c;甚至有的題目尚未AC&#xff0c;讓在掙扎中。之所以推薦計算幾何…

2013年 833c語言程序 江南大學 (A卷)

1.編寫程序實現求兩個整數最大公約數和最小公倍數. 方法一&#xff1a;輾轉相除法 算法思路&#xff1a;兩個整數a,b,其中a>b&#xff0c;求其最大公約數和最小公倍數 步驟① a%bc,其中c為余數 步驟② 若余數c為0&#xff0c;即a可以把b給整除,也就是說這里的b就是其最大公…

二十幾歲失敗的原因

1.缺乏人生目標。在研究過的人們中&#xff0c;9.98%的人沒有"人生目標"&#xff0c;這恐怕是人們失敗的最大原因。  2.自學能力不足。歷史上所謂掌握最高教育的人&#xff0c;幾乎都是"自學型"的。所謂"有教育"的人&#xff0c;不能只看成是有…

C程序生成一定范圍內的隨機數

Random numbers just numbers that lie within a range and any of the numbers can occur. 隨機數只是在一個范圍內的數字&#xff0c;任何數字都可能出現。 In programming, we come through a lot of scenarios where we need to generate random numbers. Like for dice g…