Java的IO实例
//Java的IO的一个实例
import java.io.*;
import java.util.zip.*;
public class abc5{
String temp=new String();
String t=new String();
public void readByLinefromConsoleAndPrint(){
System.out.println("==从控制台获得输入==");
try{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入一行字符:");
System.out.println(temp=in.readLine());
}
catch(IOException e){
e.printStackTrace();
}
}
public void readByLinefromFileAndPrint(){
System.out.println("==从文件获得输入==");
try{
BufferedReader in=new BufferedReader(new FileReader("abc.dat"));
temp="";
String s=new String();
while((s=in.readLine())!=null)
temp+=s+"\n";
in.close();
System.out.println(temp);
}
catch(FileNotFoundException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
}
public void readfromMemoryAndPrint(){
System.out.println("==从内存获得输入==");
try{
StringReader stringReader=new StringReader(temp);
int t;
while((t=stringReader.read())!=-1)
System.out.println((char)t);
}
catch(IOException e){
e.printStackTrace();
}
}
public void writeToFile()
{
System.out.println("==文件输出流==");
try{
BufferedReader in=new BufferedReader(new StringReader(temp));
PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("abc.dat")));
while((t=in.readLine())!=null)
o
相关文档:
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......
先看一下的java代码: class Person { private String name=""; private int age=0; public Person() { System.out.println("person无参数构造函数"); } public Person(String name,int age) { ......
今天终于把JAVA里一个比较头痛的问题——字符编码弄清晰了,所以写一篇文章来纪念一下,也为大家提供一点自己的心得。
众所周知,JAVA为了国际通用,用的是UNICODE来保存里面的字符。而UNICODE只是一个种字符集,字符的存储和表示要用到一定的字符编码格式,而与UNICODE对应的字符编码格式就是我们常看到的U ......
import java.awt.*;
import java.awt.event.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.*;
public class ElectToo extends JFrame implements ActionListener,ItemListener
{
static ElectToo frm=new ElectToo();
static Save ......
一个Java字体设置程序,包括大小,颜色,加粗,下划线,对齐,斜体的设置,很全!!! 收藏
Swing对JTextPane中字体颜色的设置
转自:http://www.blogjava.net/Swing/archive/2007/12/26/128965.html
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.a ......