io

IO(File 递归)

拈花ヽ惹草 提交于 2020-02-07 07:44:25
File概述 java.io.File类:文件和目录路径名的抽象表示形式。 用来描述电脑中文件,文件夹,以及路径类 常用的3个和File有关的单词: file:文件 directory:文件夹(目录) path:路径 File是一个与系统无关的类 File类的3个重载的构造方法 路径: window系统的目录分隔符是一个\ java中的目录分隔符是:\\或者/ 路径的分类 : 绝对路径 :以盘符开始的路径 例如:D:\\ase\\20170514\\day10 D:\\Work_EE_266\\day10\\src 相对路径: 相对于当前项目来说,路径编写的时候可以省略盘符到项目之间的路径 D:\\Work_EE_266\\day10-->src 注意:路劲不区分大小写的 File(File parent, String child) 传递路径,传递 File 类型父路径,字符串类型子路径 好处:父路径是 File 类型,父路径可以直接调用 File 类的方法 File(String parent, String child) 传递路径,传递字符串类型父路径,字符串类型的子路径 好处:单独操作父路径和子路径,使用起来比较灵活,可以把路径单独作为参数传递过来 File(String pathname) 传递路径名:可以写文件夹,也可以写到一个文件 c:\\abc c:\\abc\

I/O流总结

杀马特。学长 韩版系。学妹 提交于 2020-02-07 02:20:36
一,I/O流概述 I/O流简单的理解就是数据的输入与输出;那数据的的输入与输出又怎么理解呢? 首先我们知道,所有的数据在计算机中都是以二进制的形式存储的.我们看到的字节或者字符形式的文件都是计算机经过解析之后形成的. 那么数据的输入与输出简单地说,就是我们向计算机(通信设备)存数据和取数据的方式,这种方式包括两种,一种是字节形式的存取,一种是字符形式的存取. 那什么时候用字节,什么时候用字符呢?这是我们今天讨论的重点. 二,I/O流的体系(字符流) 如图:    I/O流的体系非常之庞大.但是我们从体系的顶层向下看的话,其实还是很好掌握的; 1)我们从体系图中可以看出 I/O流按照输入和输出来分就是: 输入流: 字节输入流:InputStream 字符输入流:Reader 输出流: 字节输出流:OutputStream 字符输出流:Writer 2)了解的内容: 当处理纯文本内容时,建议使用字符流; 当处理图像,音频文件时,使用字节流; 三,体系解析: 3.1 字符流操作文本文件: 示例1:向计算机硬盘中写入些文字; import java.io.FileWriter; import java.io.IOException; public class FileWriterDemo { //因为考虑到不同系统的的换行符号不一致,所以我们直接调用系统的换行设置 private

How multibyte string is converted to wide-character string in fxprintf.c in glibc?

て烟熏妆下的殇ゞ 提交于 2020-02-05 05:12:46
问题 Currently, the logic in glibc source of perror is such: If stderr is oriented, use it as is, else dup() it and use perror() on dup() 'ed fd . If stderr is wide-oriented, the following logic from stdio-common/fxprintf.c is used: size_t len = strlen (fmt) + 1; wchar_t wfmt[len]; for (size_t i = 0; i < len; ++i) { assert (isascii (fmt[i])); wfmt[i] = fmt[i]; } res = __vfwprintf (fp, wfmt, ap); The format string is converted to wide-character form by the following code, which I do not understand:

Android non-blocking file i/o?

自古美人都是妖i 提交于 2020-02-04 08:38:04
问题 I'm currently writing an async i/o library for Java that has a very similar API to Node.js. I could do the socket part with nio, but there seems to be no FileChannel that extends SelectableChannel so I can't do the file i/o with nio, too. In Java 7 they added AnsynchronousFileChannel, which allows non-blocking file i/o. Unfortunately, Android does not support it. Is there an equivalent class on Android to do non-blocking file io? You can find the library here: https://github.com/VanCoding

C# File.Copy Not enough quota

丶灬走出姿态 提交于 2020-02-03 09:59:13
问题 I have a large application running on a bunch of machines. Once every 5 minutes it copies a file to do some manipulation on it. The code works without a hitch almost 99.9% of the time but once every few hours I might get the error discussed here. Here's the code: try { File.Copy(fullPathName, readPathName, true); } catch (Exception exception) { .... } This code runs in its own thread but should only be one of these threads running. Here's the error I get: Encountered an unexpected exception

Java file tailer implementation

有些话、适合烂在心里 提交于 2020-02-03 03:19:46
问题 implement a java file watcher which is equivalent to tail -f somefile I've read a few similar questions. and I've seen a few options. using BufferedReader , basic idea is to use buffered reader to read from the file. if null is returned then sleep a few seconds and then continue in a infinite loop. I experimented a bit on this, my result show as long as you read to the end of the file, then getLine method will no longer give you any updates. so does this approach work at all? using random

Java file tailer implementation

坚强是说给别人听的谎言 提交于 2020-02-03 03:19:07
问题 implement a java file watcher which is equivalent to tail -f somefile I've read a few similar questions. and I've seen a few options. using BufferedReader , basic idea is to use buffered reader to read from the file. if null is returned then sleep a few seconds and then continue in a infinite loop. I experimented a bit on this, my result show as long as you read to the end of the file, then getLine method will no longer give you any updates. so does this approach work at all? using random

use the FileSystemWatcher class to document the user who is making changes

时光总嘲笑我的痴心妄想 提交于 2020-02-02 11:07:31
问题 I have a console app that checks for changes occurring on the file system. I'm trying to find out if it's possible to get the username of the individual who is doing the changes? 回答1: You'd be better off enabling auditing on the folder. Right-click the folder, go to Properties > Security tab > Advanced > Auditing tab. There are options for recording an audit log of events that happen in that folder. 回答2: No, it's not possible, the NTFS or FAT file system which is what Windows uses doesn't

How to copy a file with the ability to cancel the copy?

别等时光非礼了梦想. 提交于 2020-02-02 03:08:50
问题 I’m trying to have the program be able to cancel the copy. Therefore I can’t use Microsoft.VisualBasic.FileIO.FileSystem.CopyFile . There are some wrappers for CopyFileEx on the web such as here. However, I rather not use something I don’t understand, not wanting any unexpected results (or bugs). Is there a managed way to do this? Or perhaps a wrapper by MS (in something like Windows API CodePack)? Thanks. 回答1: Read the file in small chunks and write it out to the destination. Periodically

How to copy a file with the ability to cancel the copy?

那年仲夏 提交于 2020-02-02 03:06:50
问题 I’m trying to have the program be able to cancel the copy. Therefore I can’t use Microsoft.VisualBasic.FileIO.FileSystem.CopyFile . There are some wrappers for CopyFileEx on the web such as here. However, I rather not use something I don’t understand, not wanting any unexpected results (or bugs). Is there a managed way to do this? Or perhaps a wrapper by MS (in something like Windows API CodePack)? Thanks. 回答1: Read the file in small chunks and write it out to the destination. Periodically