当前位置:首页 » 文件管理 » stream读取文件夹

stream读取文件夹

发布时间: 2023-02-06 23:54:08

java如何用FileIputStream按行读取csv文件 求代码

FileInputStream是按字节读取文件的

按行读取的话,用BufferedReader

BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("ss.csv"));
String str = "";
while (null != (str = br.readLine())) {
System.out.println(str);
}

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (br!= null) {
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

用的相对路径,ss.csv和类放在一个文件夹里了

❷ java怎么使用io流读取一个文件夹里面

  1. 使用工具类Properties

  2. 工具类有Load()方法 用于加载文件

  3. 首先将文件写成流(输入)

    File file=new File(confPath);
    in = new FileInputStream(file);

  4. 加载流load(in)如果需要操作则完成具体操作

  5. 输出流并保存文件

    out2 = new OutputStreamWriter(new FileOutputStream(confPath),"GBK");
    cp.store(out2);


    完成

  6. 具体实例代码

    public String updateConfParam(ConfParam cpl) throws IOException {

    String error = null;
    Properties cp=new Properties();
    InputStream in= null;
    OutputStreamWriter out1=null;
    OutputStreamWriter out2=null;
    JSONObject jObj = new JSONObject();
    try {
    String confPath=validateSystem(cpl.getConfAddress()+"/"+cpl.getConfName());
    File file=new File(confPath);
    in = new FileInputStream(file);
    cp.load(in);
    out1=new OutputStreamWriter(new FileOutputStream(confPath+".bak"),"GBK");
    cp.store(out1);
    cpl.setParaOldValue(cp.getProperty(cpl.getParaKey()));
    cp.setProperty(cpl.getParaKey(), cpl.getParaValue());
    out2 = new OutputStreamWriter(new FileOutputStream(confPath),"GBK");
    cp.store(out2);

    jObj.put("paraOldValue", cpl.getParaOldValue());
    jObj.put("paraValue", cpl.getParaValue());
    } catch (FileNotFoundException e) {
    error=e.getMessage();
    } catch (IOException e1) {
    error = e1.getMessage();
    }
    finally{
    if(in !=null){
    in.close();
    }
    if(out1 !=null){
    out1.close();
    }
    if(out2 !=null){
    out2.close();
    }
    if(error != null){
    jObj.put("error", error);
    }
    }
    return jObj.toString();
    }

❸ java window和linux FileInputStream读文件路径问题

Linux系统下的文件夹路径和window下的不一样,windows下就需要写成“\\photos"因为java会把第一个"\"当成转义字符给”吃了“。但在linux下就是 “/photos”呵呵,是不是很郁闷阿。所以你的if (myFile.newFolder(path+"\\photos")) 就应该写成if (myFile.newFolder(path+"/photos"))以此类推。 public static final String FILE_SEPARATOR = System.getProperties()。getProperty("file.separator"); 文件分隔符(在 UNIX 系统中是“/”),window 是"\" 为了程序的可移植性,使用File.separator来写路径。 File(String pathname) 通过将给定路径名字符串转换为抽象路径名来创建一个新 File 实例。 public static final String separator 与系统有关的默认名称分隔符,为了方便,它被表示为一个字符串。此字符串只包含一个字符,即 separatorChar。 public static final char separatorChar 与系统有关的默认名称分隔符。此字段被初始化为包含系统属性 file.separator 值的第一个字符。在 UNIX 系统上,此字段的值为 '/';在 Microsoft Windows 系统上,它为 '\\'。 注意: 路径名字符串与抽象路径名之间的转换与系统有关。将抽象路径名转换为路径名字符串时,每个名称与下一个名称之间用一个默认分隔符 隔开。默认名称分隔符由系统属性 file.separator 定义,可通过此类的公共静态字段 separator 和 separatorChar 使其可用。将路径名字符串转换为抽象路径名时,可以使用默认名称分隔符或者底层系统支持的任何其他名称分隔符来分隔其中的名称System.getProperty("user.dir") 获取工程路径名System.getProperty("file.separator").equals("/") 判断linux的方法。用File.separator这个可以直接替换路径问题,不需要判断

❹ istream 最大能读取多大文件

3个G的文件。istream是最新研发的文件读取方式,与其他的读取方式不同,其采用的是数字读取,最大能3个G的文件,保持流畅不卡顿。

❺ c# 操作文件夹问题,先判断是否存在这个文件夹,存在则连同子目录一同删除,然后再创建新的目录,错误:

"另一进程使用"的意思就是,其他地方已经有Stream读取这个文件,而且改Stream未释放Close().你这里用的是DirectoryInfo我不是特别清楚.请你检查一下有没有这种情况.

另外DirectoryInfo没有用过.不过请你做两件事情用用两个DirectoryInfo对象.if里的内容重写:
if(dirInfo.Exists)
{
dirInfo.Delete(true);
dirInfo = new DirectoryInfo(indexPath);
dirInof.Create();
}

删除的dirInfo已经占用了这个文件夹,所以先关闭这个dirInfo之后再初始化一个dirInfo

❻ java getresourceasstream怎么读取中文文件

J2SE中的getResourceAsStream用法有以下几种:
第一: 要加载的文件和.class文件在同一目录下,例如:com.x.y 下有类me.class ,同时有资源文件myfile.xml
那么,应该有如下代码:
me.class.getResourceAsStream("myfile.xml");
第二:在me.class目录的子目录下,例如:com.x.y 下有类me.class ,同时在 com.x.y.file 目录下有资源文件myfile.xml
那么,应该有如下代码:
me.class.getResourceAsStream("file/myfile.xml");

第三:不在me.class目录下,也不在子目录下,例如:com.x.y 下有类me.class ,同时在 com.x.file 目录下有资源文件myfile.xml
那么,应该有如下代码:
me.class.getResourceAsStream("/com/x/file/myfile.xml");
总结一下,可能只是两种写法
第一:前面有 “ / ”
“ / ”代表了工程的根目录,例如工程名叫做myproject,“ / ”代表了myproject
me.class.getResourceAsStream("/com/x/file/myfile.xml");
第二:前面没有 “ / ”
代表当前类的目录
me.class.getResourceAsStream("myfile.xml");
me.class.getResourceAsStream("file/myfile.xml");
注:
getResourceAsStream读取的文件路径只局限与工程的源文件夹中,包括在工程src根目录下,以及类包里面任何位置,但是如果配置文件路径是在除了源文件夹之外的其他文件夹中时,该方法是用不了的。

❼ 关于用stream读取文件(如何将远程文件放入Stream) ASP.NET

System.Net.WebClient c = new System.Net.WebClient(); byte[] b = c.DownloadData( "http://www.aa.com/aa.doc "); System.IO.MemoryStream ms = new System.IO.MemoryStream(); ms.Write(b, 0, b.Length);

❽ java 中inputstream 和outputstream 怎么进行文件的读取写入的

你可以这样理解:
FileInputStream in = new FileInputStream("E:\\a.zip");
FileInputStream 顾名思义,就是写入。这句话将a.zip做编码后放到in,要用a.zip的时候就使用in读出来。

FileOutputStream os = new FileOutputStream("e:\\b.zip");
FileOutputStream顾名思义,就是读出,读出的话就要指定读出的目的地,e:\\b.zip便是目的地。

while(in.read(bt) != -1)
{
os.write(bt);
}
这段代码就是从in中读出编码后的文件内容,然后通过os写入b.zip.

❾ vb中streamreader怎么读取文件

读取文件,并写入数组及降序排序:
Dim file As New System.IO.StreamReader("data1.txt")
Dim words As String = file.ReadToEnd()
file.Close()
Dim b() As String
Dim temp As Integer
Dim str1 As String
str1 = ""
b = Split(words, " ")
Dim c() As Integer

Dim l As Integer
l = UBound(b)
ReDim c(l)

For i = 1 To l
c(i) = Val(b(i - 1))
Next
For i = 1 To l
For j = 1 To l - i
If c(j) < c(j + 1) Then
temp = c(j + 1)
c(j + 1) = c(j)
c(j) = temp
End If
Next j
Next i
For i = 1 To l
str1 = str1 & c(i) & " "
Next
MsgBox(str1)

热点内容
武汉中南医院无线网密码是多少 发布:2024-05-07 11:20:22 浏览:356
如何把域名指向到指定服务器ip 发布:2024-05-07 10:48:49 浏览:365
base64javaphp 发布:2024-05-07 10:30:07 浏览:849
抖音青少年模式的密码是哪里的 发布:2024-05-07 10:05:27 浏览:752
tmp文件怎么解压 发布:2024-05-07 09:59:49 浏览:939
安卓手机如何提升录歌音质 发布:2024-05-07 09:49:55 浏览:331
指法运算法 发布:2024-05-07 09:24:26 浏览:195
兜享花为什么服务器错误 发布:2024-05-07 09:12:55 浏览:126
西门子编程仿真软件 发布:2024-05-07 09:12:04 浏览:128
脚本举例 发布:2024-05-07 09:04:41 浏览:819