java如何调取数据库中的数据,(java怎么调用数据库)

如题所述

下面的代码是读取文本文件的例子,程序会读取text.txt文件,并将它的内容显示出来。

1importjava.io.;

2importjava.io.File;

3importjava.io.FileReader;

4importjava.io.;

5importjava.io.IOException;

6

7publicclass

8{

9publicstaticvoidmain(String[]args)

10{

11Filefile=newFile("test.txt");

12contents=new();

13reader=null;

14

15try

16{

17reader=new(newFileReader(file));

18Stringtext=null;

19

20//repeatuntilalllinesisread

21while((text=reader.readLine())!=null)

22{

23contents.append(text)

24.append(System.getProperty(

25"line.separator"));

26}

27}catch(e)

28{

29e.();

30}catch(IOExceptione)

31{

32e.();

33}finally

34{

35try

36{

37if(reader!=null)

38{

39reader.close();

40}

41}catch(IOExceptione)

42{

43e.();

44}

45}

46

47//showfilecontentshere

48System.out.println(contents.toString());

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网