meanwhilee((nread=read(f)WSADATAwd;

while((int b = in.read()) != -1) 错在哪里啊?_百度知道
while((int b = in.read()) != -1) 错在哪里啊?
FileInputStream in =int b = 0;while(( b = in.read()) != -1) {}我分开写编译就好了。为什么啊?是java语言!
提问者采纳
while是循环,你写在里面每次都会有个
int b= in.read();相当于你写下代码 int b=0; 试一下编译能不能通过,会重定义错误的。
提问者评价
其他类似问题
按默认排序
其他1条回答
in = null?这样运行时肯定会抛出一个空指针访问异常,异常会指向 in.read()
FileInputStream in =这个我们先不管,我是用来说明下面的in再说java里没有指针呀。。。。。。我是问int b定义在while()中就不行。为什么》
噢!怪我没看清楚问题,楼下那位是正确的。while((int b = in.read()) != -1)这样做就相当于你定义了多个同名变量b,当循环次数大于1时,这自然是错误。它不像for循环,for循环中for(int i=0;;)的int i=0只执行一次。还有,如果in = null,后面引用in 时肯定会抛出&java.lang.NullPointerException&异常,即空指针异常。答案当给楼下的。
while的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) {}干什么用的?_百度知道
SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) {}干什么用的?
在三层架构中怎么读取表中数据显示到页面上?或者在三层中还有其它方法读取显示数据?请高手赐教!
提问者采纳
这个是取出所有数据用的。三层架构读取基本上常用的就是reader
提问者评价
其他类似问题
sqldatareader的相关知识
其他2条回答
用来遍历读取出的数据库中的数据
可以用DataTable
您可能关注的推广
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁Java中的 while((i=in.read())!=-1) &br/&-1是什么意思呢?&br/&请教各位大大。&br/&谢谢、
Java中的 while((i=in.read())!=-1) -1是什么意思呢?请教各位大大。谢谢、
就是没读到值
的感言:谢谢。
等待您来回答
编程领域专家linux read 和write的程序帮我逐条解释一下,新人不懂。 一定要详细些。_百度知道
linux read 和write的程序帮我逐条解释一下,新人不懂。 一定要详细些。
#include &unistd.h&#include &fcntl.h&int main(){
char buffer[1024];
fdin = open(&temp1.txt&, O_RDONLY);
fdout = open(&temp2.txt&, O_WRONLY | O_CREAT | O_TRUNC, 0644);
while((nread = read(fdin, buffer, 1024)) & 0)
if(write(fdout, buffer, nread) & nread)
close(fdin);
close(fdout);
close(fdin);
close(fdout);}
提问者采纳
#include &unistd.h&//引入头文件LINUX/UNIX下的,为函数read/write用 #include &fcntl.h&//为函数open用int main(){
int fdin,//定义文件描述符一个文件进的,一个出的
ssize_//定义字节大小
char buffer[1024];//定义缓冲区字节大小
fdin = open(&temp1.txt&, O_RDONLY);//打开当前目录下的文件temp1.txt并且以只读方式打开
fdout = open(&temp2.txt&, O_WRONLY | O_CREAT | O_TRUNC, 0644);//打开当前目录下的文件temp2.txt,以写方式打开,并且是没有就创建,有的话就全部覆盖掉,0644是该文件的权限 就是rwx(读/写/执行),应该明白撒
while((nread = read(fdin, buffer, 1024)) & 0)//从文件描述符里读取数据到buffer里,当读取到的字节大于0时,言外之意就是要读取完文件temp1.txt
if(write(fdout, buffer, nread) & nread)//把从文件temp1.txt里读到的数据一直往文件temp2.txt里写,直到写完全部temp1.txt的数据
close(fdin);//关闭文件描述符
close(fdout);//关闭文件描述符
close(fdin);关闭文件描述符
close(fdout);关闭文件描述符/*基于程序的完整性,最好加上返回语句
return 0;//表示程序正常结束*/}不知道够不够详细呢兄弟····
提问者评价
够了谢谢你的帮助 我不是专业学这个的所以听不大懂专业术语。
其他类似问题
linux的相关知识
其他2条回答
逐条????什么叫逐条。。。。。您能说明白点么。。。。如果是笼统点的话。或许能帮你解答。但是如果详细的话。。。。我想解释完了。您也用不着了
#include &unistd.h&#include &fcntl.h&int main(){
char buffer[1024];
fdin = open(&temp1.txt&, O_RDONLY);
//以只读方式打开文件temp1.txt,获得句柄fdin
fdout = open(&temp2.txt&, O_WRONLY | O_CREAT | O_TRUNC, 0644);//以只写方式打开文件temp2.txt,获得句柄fdout
while((nread = read(fdin, buffer, 1024)) & 0)
//通过句柄fdin从temp1.txt中读取数据到buffer数组中,读到的数据量大小为nread个字节,如果nread&0则表示能读到,所以还要继续循环
if(write(fdout, buffer, nread) & nread)
//把buffer数组中数据写进fdout句柄代表的temp2.txt中
close(fdin);
//关闭fdin句柄
close(fdout);//关闭fdout句柄
close(fdin);
close(fdout);}
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁一、文件描述符
函数名称:fileno
函数原型:int _fileno( FILE *stream );  
函数功能:用来取得指定的文件流所使用的文件描述符  
返回值:某个数据流的文件句柄  
头文件:stdio.h
#include &stdio.h&
int main(){
printf(&the file descriptor for stdin is %d\n&,fileno(stdin));
printf(&the file descriptor for stdout is %d\n&,fileno(stdout));
printf(&the file descriptor for stderr is %d\n&,fileno(stderr));
二、open函数
函数名称:open
函数原型:int open(const char *pathname, int flags);
&&&&& & & & & & & int open(const char *pathname, int flags, mode_t mode);
函数功能:打开或创建一个文件
返回值:&& 成功则返回文件描述符,否则返回 -1.(open返回的文件描述符一定是最小的未被使用的描述符。)
#include &unistd.h&
#include &sys/types.h&
/*for open*/
#include &sys/stat.h&
/*for open*/
#include &fcntl.h&
/*for open*/
#include &stdlib.h&
/*for perror exit */
#include &stdio.h&
/*for perror*/
#define ERR_EXIT(m) \
perror(m); \
exit(EXIT_FAILURE); \
} while(0)
int main(void)
umask(0);//为进程设置文件模式创建屏蔽字,设为0表示不屏弊
fd = open(&test.txt&, O_WRONLY | O_CREAT, 666);//666表示所有者,所属组,其他用户都可以读写
if (fd == -1)
ERR_EXIT(&open error&);
printf(&open succ\n&);
&&&&&&&&&& 运行之后生成的文件:
函数名称:read
函数原型:ssize_t read(int fd, void *buf, size_t count);&&&&& & & & & & &
函数功能:从fd指向的文件的当前偏移量至多读count个字节到buf中。成功返回写入buf的字节数。出错时则返回-1,
&&&&&&&&&&&&&&&&&&& 并设置errno。
返回值:&& 成功则返回文件描述符,否则返回 -1.(open返回的文件描述符一定是最小的未被使用的描述符。)
函数名称:write
函数原型:ssize_t write(int fd, const void *buf, size_t count);& & & &
函数功能:函数向打开的设备或文件中写数据.
返回值:&& 成功返回写入的字节数,出错返回-1并设置errno写常规文件时,write的返回值通常等于请求写的字节数
&&&&&&&&&&&&&&&&&& count,而向终端设备或网络写则不一定。
#include &stdio.h&
/*for fprintf*/
#include &unistd.h&
/*for read write*/
#include &sys/types.h&/*for open*/
#include &sys/stat.h&
/*for open*/
#include &fcntl.h&
/*for open*/
#include &stdlib.h&
/*for EXIT_FAILURE*/
#define ERR_EXIT(m) \
perror(m);\
exit(EXIT_FAILURE);\
int main(int argc,char* argv[]){
if(argc!=3){
fprintf(stderr,&Usage %s src dest\n&,argv[0]);
exit(EXIT_FAILURE);
infd = open(argv[1],O_RDONLY);
if(infd==-1){
ERR_EXIT(&open src error&);
if((outfd=open(argv[2],O_WRONLY|O_CREAT|O_TRUNC,644))==-1){
ERR_EXIT(&open dest error&);
char buf[1024];
while((nread=read(infd,buf,1024))&0){
if((nwrite=write(outfd,buf,nread))==-1){
ERR_EXIT(&write error&);
close(infd);
close(outfd);
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:7591次
排名:千里之外
原创:10篇
转载:38篇
(1)(1)(1)(16)(3)(1)(6)(6)(2)(2)(8)(2)

我要回帖

更多关于 meanwhile 的文章

 

随机推荐