Home > Net >  Unable to transfer from "bool" to "System. Text. Encoding"
Unable to transfer from "bool" to "System. Text. Encoding"

Time:09-18

Novice to solve, don't know this section right...
 
Public void the write ()
{
Bool A=false;
FileStream fs=new FileStream (Properties. Resources. Maxscore, FileMode. Create);
StreamWriter sw=new StreamWriter (fs, A);
}

I want to use it to a file is written to, but in the second parameter StreaWriter appeared error, is like this:
Severity code shows the project file line prohibits display status
Error CS1503 parameter 2: from "bool" into "System. Text. Encoding" Game2048 F: \ \ c # learning through four extension code \ \ control experiment Game2048 \ Game2048 \ Form1 cs 201 activity

Want to ask that how to solve the

CodePudding user response:

There is something wrong with the code below is my baidu search, go to the baidu search, don't have a question to ask, learn to think more, rather than ask someone else to answer
 
//c # file stream to write the file, the default add FileMode. Append
String MSG="okffffffffffffffff";
Byte [] myByte=System. Text.. Encoding UTF8. GetBytes (MSG);
Using (FileStream fsWrite=new FileStream (@ "D: \ 1. TXT", FileMode, Append))
{
FsWrite. Write (myByte, 0, myByte. Length);
};
//c # file stream to read the file
Using (FileStream fsRead=new FileStream (@ "D: \ 1. TXT", FileMode. Open))
{
Int fsLen=(int) fsRead. Length;
Byte [] heByte=new byte [fsLen];
Int r=fsRead. Read (heByte, 0, heByte. Length);
. String myStr=System. Text. Encoding UTF8. Get string (heByte);
Console. WriteLine (myStr);
The Console. ReadKey ();
}

CodePudding user response:

Elder brother,,, I have tried on baidu things... Is because did not find useful, just to ask the

CodePudding user response:

refer to the second floor limit___lxz response:
,,, I have tried on baidu things... Is because did not find useful, just to ask the

You can try the code 2, a is written, is a read, baidu on a lot of ah, kao come and can directly use, don't know what you are baidu search

CodePudding user response:

Look at the constructor streamwriter, according to the need to select the corresponding constructor, introduced to the corresponding parameter
Your parameter in the constructor, since you first parameter to the stream, but you could see the constructor which accord with the first parameter is the stream,
The first 1.3.5.7 is conform to, and then you look at the rest of the second parameter, you press f12 streamwriter see how to define the

CodePudding user response:

The first parameter is the path of type string, the second parameter is the append bool type;
The first parameter is the Stream type of document flow, the second parameter is the Encoding type of coding object;
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Public StreamWriter (string path, bool append)
Members of the System. IO. StreamWriter

Abstract:
Using the default encoding and buffer size for the specified file initialization System. IO. StreamWriter a new instance of a class, if the file exists, then it can be covered or to its additional, if the file does not exist, this constructor will create a new file,

Parameters:
Path: to write the full file path,
Append: if you want to append data to the file, it is true; If you want to overwrite the file, it is false, if the specified file does not exist, this parameter is invalid, and the constructor will create a new file,

Exception:
System. UnauthorizedAccessException: access denied,
System. ArgumentException: the path is empty,
Or
The path contains the names of the system equipment (com1, com2, etc.),
System. ArgumentNullException: path is null,
System. IO. DirectoryNotFoundException: the specified path is invalid (for example, it is not mapped drives),
System. IO. IOException: path contains incorrect or invalid filename, directory name, or volume label syntax,
System. IO. PathTooLongException: the specified path and/or file name exceeds the maximum length of the System definition,
System. Security. SecurityException: the caller without the required permissions,

Features:
[System. Security. SecuritySafeCriticalAttribute]

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Public StreamWriter (System. IO Stream, Stream, System. Text. The Encoding Encoding)
Members of the System. IO. StreamWriter

Abstract:
Using the specified encoding and the default buffer size for the specified flow initialization System. IO. StreamWriter new instance of the class,

Parameters:
Are incorporated into the stream, stream:
Encoding: the character encoding to use,

Exception:
System. ArgumentNullException: stream or encoding is null,
System. ArgumentException: stream cannot write,

Features:
[System. Security. SecuritySafeCriticalAttribute]

CodePudding user response:

Tips to tell you! Want to use the System. Text. Encoding enumeration type, can't use A bool type variable,
 StreamWriter sw=new StreamWriter (fs, System. Text. Encoding. UTF8); 
  • Related