原来文件读取的是二进制字节内容,对应的是字母的acII值,如下用例可以让你看到取到的到底时什!!
public static void main(String args[]) throws IOException{
File file=new File("E:/j2ee-project/work-space-01/edu/src/trm/com/hnyyzw/trm/model/TrmFile.java");
if(file.exists()){
FileInputStream inputStream = new FileInputStream(file);
int size=0;
System.out.println("inputstream available:"+(double)inputStream.available()/1024);
for(double i=0;(size=inputStream.read())!=-1;i++){
System.out.println((char)size);
System.out.println("xxx:"+size);
}
}
}
分享到:
相关推荐
聊天室(用java代码编写,用到Socket,serverSocket,FileInputStream.....) 可以实现公聊与私聊!字体调色,大小....(界面手工编写) 虽然功能简单但也是可以借鉴的,
文件字节输入流,里面有文件字节输入流的相关要点以及经典案例
int bytesRead = bis.read(lastBytes); // 读取最后16个字节 StringBuilder hexString = new StringBuilder(); for (byte b : lastBytes) { if (bytesRead > 0) { hexString.append(Integer.toHexString(0xFF ...
while ((length = fStream.read(buffer)) != -1) { ds.write(buffer, 0, length); } ds.writeBytes(end); ds.writeBytes(twoHyphens + boundary + twoHyphens + end); ``` 5. **关闭流**: 在写入所有数据...
while ((length = fis.read(buffer)) > 0) { response.getOutputStream().write(buffer, 0, length); } fis.close(); } else { response.getWriter().println("File not found!"); } } } ``` 在这个例子中...
fileinputstream.read(bytes); fileinputstream.close(); templateContent = new String(bytes); templateContent = templateContent.replaceAll("###title###", title); templateContent = templateContent....
while ((length = fileInputStream.read(buffer)) != -1) { MD5.update(buffer, 0, length); } return new String(Hex.encodeHex(MD5.digest())); } catch (Exception e) { e.printStackTrace(); ...
while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } } } ``` 在这个例子中,我们使用缓冲区来提高读写效率,每次从源文件读取一定数量的字节,然后写入目标文件。 在实际开发中,字节...
`FileInputStream`是Java I/O流的一部分,常用于读取文件内容。在Android环境中,`FileInputStream`可以帮助我们从设备的内部或外部存储读取文件。本文将详细讨论`FileInputStream`工具类及其在Android中的使用。 ...
char data3 = (char) fileInputStream.read(); ``` 2. **使用for循环**:通过循环调用`read()`方法,逐个读取并打印字符。这种方式效率较低,因为每次循环都会调用一次`read()`。示例代码如下: ```java for ...
1. 构造方法:public FileInputStream(String name) throws FileNotFoundException:通过打开一个到实际文件的连接来创建一个 FileInputStream,该文件通过文件系统中的文件名 name 指定。 2. 构造方法:public ...
fileInputStream.read(a); out.write(a); out.flush(); out.close(); fileInputStream.close(); } } } } ``` Step 3: 在 JSP 页面中调用 Servlet 在 JSP 页面中,可以使用超链接来调用 Servlet,实现文件...
sourceImg = javax.imageio.ImageIO.read(is); } catch (IOException e1) { e1.printStackTrace(); // return rect; } System.out.println("width = " + sourceImg.getWidth() + "height = " + ...
它继承自`InputStream`,提供了一套基本的读取方法,如`read()`用于读取单个字节,`read(byte[])`用于读取多个字节到缓冲区。 在文件上传过程中,`File`和`FileInputStream`通常一起使用。用户上传的文件首先会被...
JavaAdvance复习题汇总 1.java语言提供处理不同类型流的类的包是(D) a)java.sql b) java.util c) java.math d) java.io ...A.FileInputStream B.FilterInputStream C.ByteArrayInputStream D.ObjectInputStream
根据提供的文件信息,本篇文章将围绕“Java经典编程100例之FileInputStream的应用”这一主题展开,深入探讨FileInputStream类的基本概念、使用方法及其在实际编程中的应用场景。 ### Java经典编程100例——...
int len = fis.read(buf); System.out.println(new String(buf, 0, len)); fis.close(); ``` 四、BufferedOutputStream 和 BufferedInputStream BufferedOutputStream 和 BufferedInputStream 是 Java IO 中的过滤...
while ((bytesRead = fileInputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } fileInputStream.close(); outputStream.flush(); outputStream.close(); socket.close(); ``` 对于...
int bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead > 0) { out.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min...