本文介绍了我希望在c#中使用Stream阅读器分割文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我的问题是代码没有正常工作,我希望使用Stream阅读器在twoparts中分割文件c# 使用System; 公共类SplitFile { internal static int sizeOfFiles; // JAVA到C#转换器警告:方法'throws'子句在.NET中不可用: // ORIGINAL LINE:public static String [] splitFile(java.io.File f ,int noOfSlaves)抛出java.io.IOException public static string [] splitFile(File f,int noOfSlaves) { BufferedInputStream bis = new BufferedInputStream( new FileInputStream(f)); FileOutputStream @out; string name = f.Name; int partCounter = 1; int totalsize = bis.available(); Console.WriteLine(主文件总大小:+ totalsize); // int sizeOfFiles = 1024 * 1024; // 1MB sizeOfFiles = totalsize / noOfSlaves; Console.WriteLine(sizeOfFiles:+ sizeOfFiles); sbyte [] buffer = new sbyte [sizeOfFiles]; int tmp = 0; int i = 0; int j = 1; string [] fileArray = new string [2]; while((tmp = bis.read(buffer))> 0) { fileArray [i] = f.Parent +\\+ name +。 + string.Format({0:D3},j); 文件newFile = new File(f.Parent +\\+ name +。+ string.Format({0:D3},partCounter ++)); i ++; j ++; newFile.createNewFile(); @out = new FileOutputStream(newFile); @ out.write(buffer,0,tmp); @ out.close(); } return fileArray; } // JAVA到C#转换器警告:方法'throws'子句在.NET中不可用: // ORIGINAL LINE:public static void main (String [] args)抛出java.io.IOException public static void Main(string [] args) { splitFile(new file(c:\\data.txt ),2); } } 请帮帮我。解决方案 现在我明白他是什么了意味着。 这已成为一种真正的滥用。做你正在做的事情会适得其反,浪费时间充其量。 使用 System.IO.StreamReader的问题非常非常简单。您应该忘记Java代码并从其目标开始编写代码,而不是从现有代码编写代码。如果您解释这个目标并解释问题,我们将很乐意为您提供帮助。但是如果您只是简单地阅读原始文档,那么很可能您可以轻松地将其正确地理解: http://msdn.microsoft.com/en-us/library/system.io.streamreader%28v=vs.110%29.aspx [ ^ ]。 -SA my probelm is code is properly not working,I want Split file in twoparts using Stream reader in c#using System;public class SplitFile{ internal static int sizeOfFiles;//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET://ORIGINAL LINE: public static String[] splitFile(java.io.File f, int noOfSlaves) throws java.io.IOExceptionpublic static string[] splitFile(File f, int noOfSlaves){BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));FileOutputStream @out;string name = f.Name;int partCounter = 1;int totalsize = bis.available();Console.WriteLine("Master File total size: " + totalsize);// int sizeOfFiles = 1024 * 1024;// 1MBsizeOfFiles = totalsize / noOfSlaves;Console.WriteLine("sizeOfFiles: " + sizeOfFiles);sbyte[] buffer = new sbyte[sizeOfFiles];int tmp = 0;int i = 0;int j = 1;string[] fileArray = new string[2];while ((tmp = bis.read(buffer)) > 0){ fileArray[i] = f.Parent + "\\" + name + "." + string.Format("{0:D3}", j);File newFile = new File(f.Parent + "\\" + name + "." + string.Format("{0:D3}", partCounter++)); i++;j++;newFile.createNewFile();@out = new FileOutputStream(newFile);@out.write(buffer, 0, tmp);@out.close();}return fileArray;}//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET://ORIGINAL LINE: public static void main(String[] args) throws java.io.IOExceptionpublic static void Main(string[] args){splitFile(new File("c:\\data.txt"), 2);}}please help me. 解决方案 Now I understand what he meant.This is becoming a real abuse. Doing what you are doing is counter-productive, the waste of time at best.The problem of using System.IO.StreamReader is really, really simple. You should just forget your Java code and write the code starting from the goal of it, not from existing code. If you explain such goal and explain the problem, we will gladly help you. But it's very likely that you can easily put it right if you simply read original documentation with attention: http://msdn.microsoft.com/en-us/library/system.io.streamreader%28v=vs.110%29.aspx[^].—SA 这篇关于我希望在c#中使用Stream阅读器分割文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-15 10:42