java read file to array
时间:2014-02-19
来源:互联网
我想READ FILE DATA TO ARRAY,compile 无问题,但一RUN就出现以下画面:

咩野原因呢?另外我想将两个CLASS写埋入一个CLASS,即READFILE改用METHOD,应该点写呢?
THANKS 各位CHING指教。
// ReadFile.java
package javareadtextfile;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
class ReadFile
{
public String[] readLines(String filename) throws IOException
{
FileReader fileReader = new FileReader(filename);
BufferedReader bufferedReader = new BufferedReader(fileReader);
List<String> lines = new ArrayList<String>();
String line = null;
while ((line = bufferedReader.readLine()) != null)
{
lines.add(line);
}
bufferedReader.close();
return lines.toArray(new String[lines.size()]);
}
}
public class JavaReadTextFile
{
public static void main(String[] args)
{
ReadFile rf = new ReadFile();
// The text file location of your choice
String filename = "number.txt";
try
{
String[] lines = rf.readLines(filename);
for (String line : lines)
{
System.out.println(line);
}
}
catch(IOException e)
{
// Print out the exception that occurred
System.out.println("Unable to create "+filename+": "+e.getMessage());
}
}
}
[ 本帖最后由 I_love_IT 於 2014-1-17 03:12 PM 编辑 ]

咩野原因呢?另外我想将两个CLASS写埋入一个CLASS,即READFILE改用METHOD,应该点写呢?
THANKS 各位CHING指教。
// ReadFile.java
package javareadtextfile;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
class ReadFile
{
public String[] readLines(String filename) throws IOException
{
FileReader fileReader = new FileReader(filename);
BufferedReader bufferedReader = new BufferedReader(fileReader);
List<String> lines = new ArrayList<String>();
String line = null;
while ((line = bufferedReader.readLine()) != null)
{
lines.add(line);
}
bufferedReader.close();
return lines.toArray(new String[lines.size()]);
}
}
public class JavaReadTextFile
{
public static void main(String[] args)
{
ReadFile rf = new ReadFile();
// The text file location of your choice
String filename = "number.txt";
try
{
String[] lines = rf.readLines(filename);
for (String line : lines)
{
System.out.println(line);
}
}
catch(IOException e)
{
// Print out the exception that occurred
System.out.println("Unable to create "+filename+": "+e.getMessage());
}
}
}
[ 本帖最后由 I_love_IT 於 2014-1-17 03:12 PM 编辑 ]
作者: I_love_IT 发布时间: 2014-02-19
引用:原帖由 I_love_IT 於 2014-1-17 03:11 PM 发表
我想READ FILE DATA TO ARRAY,compile 无问题,但一RUN就出现以下画面:
3054552
咩野原因呢?另外我想将两个CLASS写埋入一个CLASS,即READFILE改用METHOD,应该点写呢?
THANKS 各位CHING指教。
// ...
comment out following line我想READ FILE DATA TO ARRAY,compile 无问题,但一RUN就出现以下画面:
3054552
咩野原因呢?另外我想将两个CLASS写埋入一个CLASS,即READFILE改用METHOD,应该点写呢?
THANKS 各位CHING指教。
// ...
package javareadtextfile;
[ 本帖最后由 form5 於 2014-1-17 08:49 PM 编辑 ]
作者: form5 发布时间: 2014-02-19
引用:原帖由 form5 於 2014-1-17 08:47 PM 发表
comment out following line
package javareadtextfile;
TAHNKS CHINGcomment out following line
package javareadtextfile;

作者: I_love_IT 发布时间: 2014-02-19
Computer programs often need to read data that was prepared by a different program or even a different system.
This data is obtained from data storage devices such as hard disks, floppy disks, CD-ROM, magnetic tape and information servers on a network.
There are many generations of data storage devices an many kinds of computer systems that use them.
The specifics of each situation depend upon the technology of the device, the computer system, the language, the server and the network.
We will focus on a few principles and techniques that can be used immediately and which create a foundation for future work in this area.
IDL has tools that permit data to be read and written to files.
The details that depend on the hardware and operating system are largely hidden from the user.
We will concentrate on a subset of the tools that provide basic functionality.
Further information can be obtained by reading the section Building IDL Applications -- Files Input and Output found under the Contents tab in IDL Online Help.
_________
The basic steps in reading data from a file are:
Tell the program where to find the data.
Open a path to the data.
Set up the program variables to access the data
Read the data
Close the data path
This data is obtained from data storage devices such as hard disks, floppy disks, CD-ROM, magnetic tape and information servers on a network.
There are many generations of data storage devices an many kinds of computer systems that use them.
The specifics of each situation depend upon the technology of the device, the computer system, the language, the server and the network.
We will focus on a few principles and techniques that can be used immediately and which create a foundation for future work in this area.
IDL has tools that permit data to be read and written to files.
The details that depend on the hardware and operating system are largely hidden from the user.
We will concentrate on a subset of the tools that provide basic functionality.
Further information can be obtained by reading the section Building IDL Applications -- Files Input and Output found under the Contents tab in IDL Online Help.
_________
The basic steps in reading data from a file are:
Tell the program where to find the data.
Open a path to the data.
Set up the program variables to access the data
Read the data
Close the data path
作者: loko2014 发布时间: 2014-02-19
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28