易截截图软件、单文件、免安装、纯绿色、仅160KB

java 文件读写_FileInputStream_File

package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test {
 public static void main(String arg[]) {
  String fileName = "E:\\share\\test.txt";
  File file = new File(fileName);
  String writeData = "HelloWorld!\r\nnihao我的内存是2G的 ";
  byte[] byteOutData = writeData.getBytes();
  byte[] byteInData = new byte[20];
  int length = 0;
  if (file.isFile()) {
   file.delete();
  }
  try {
   if (file.createNewFile() && file.canWrite()) {
    FileOutputStream fileOutStream = new FileOutputStream(file);
    fileOutStream.write(byteOutData);
    fileOutStream.close();
   }
   if (file.canRead()) {
    FileInputStream fileInStream = new FileInputStream(file);
    while ((length = fileInStream.read(byteInData)) != -1) {
     System.out.print(new String(byteInData, 0, lenght));
    }
    fileInStream.close();
   }
  } catch (IOException e) {
   System.out.println("IOException occur");
   e.getMessage();
  }
 }
}


相关文档:

Java面试题(8)

123、设计4个线程,其中两个线程每次对j增加1,另外两个线程对j每次减少1。写出程序。
以下程序使用内部类实现线程,对j增减的时候没有考虑顺序问题。
public class ThreadTest1{
   private int j;
   public static void main(String args[]){
ThreadTest1 tt=new ThreadTest1();
Inc inc=tt. ......

JAVA初始化的陷阱

为了说明这个问题先给大家出个问题吧:
请看代码:
public abstract class A {
public A() {
initMethod();
}
public abstract void initMethod();
}
public class B extends A {
static String staticStr = "static1";
private String testStr = "Test1";
/*
* (non-Javadoc)
*
* @see A#in ......

Java读取配置文件

import java.util.Properties;
public class ConfigReader {
private static Properties cache = new Properties();
static{
   try {
    cache.load(ConfigReader .class.getClassLoader().getResourceAsStream("config.properties"));
   } catch (Exception e) {
 &nbs ......

线程安全的Singleton模式的Java实现

public class Factory {
private static Factory factory;
private static Object classLock=Factory.class;
   private Factory(){}
   public static Factory getFactory(){
      synchronized(classLock){
          ......

采用JAVA组件显示本地图片


程序设计中经常会碰到用组件来显示图片的情况,    可以显示图片的组件有很多,如awt包中的button,label,panel等都可以在其上面放置图片.图片又可分为两类,一类是放置于button等组件上的ImageIcon(图标),另一类是可以放置在panel等组件上的较大的图片Image。
从本地计算机中读取图片的方法也有很多,比如, ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号