关于IO,我有两个问题.
答:在教程和一些StackOverflow答案中,他们声称FileInputStream没有缓冲.真的吗 ?
以下代码用于FileInputStream将数据读入字节数组(1024字节)
class Test {
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("./fos.txt");
FileOutputStream fos = new FileOutputStream("./copy.txt");
byte[] buffer = new byte[1024]; // Is this a buffer ?
int len;
while ((len = fis.read(buffer))!= -1) {
fos.write(buffer);
}
fos.close();
fis.close();
}
}
Run Code Online (Sandbox Code Playgroud)
从API,有一行:
public int read(byte b [])抛出IOException
- @param b:读取数据的缓冲区.
B.如果它们都是缓冲的,它们都将数据放入缓冲区,并从缓冲区中获取数据,那里的确BufferedInputStream比FileInputStream哪个地方更快?
谢谢
我已经为此挣扎了很长时间。我们都知道箭头函数简化了语法,如下所示:
A. 箭头函数:
onClick={() => toggleTodo(todo.id)}
Run Code Online (Sandbox Code Playgroud)
B. 展开箭头函数:
onClick={() => {
// we can see there is a return keyword here. can I just remove the return keyword ?
return toggleTodo(todo.id);
^^^^^^
}}
Run Code Online (Sandbox Code Playgroud)
在官方 redux 教程中,文件AddTodo.js:
import React from 'react'
import { connect } from 'react-redux'
import { addTodo } from '../actions'
const AddTodo = ({ dispatch }) => {
let input
return (
<div>
<form
onSubmit={e => { // focus on this line
e.preventDefault()
dispatch(addTodo(input.value)). …Run Code Online (Sandbox Code Playgroud) 我目前正在学习指针,但我有几个问题:
当我们说int a[] = {10, 11}; int *p = a,编译器将为指针分配内存p(指向数组的第一个地址).但是如果我们说p + 1,这是否意味着某些内存已经被一个名为p + 1?的新指针初始化了?
如果上面的答案是否定的,即没有分配内存p + 1:当我们使用时*(p + 1),我们仍然可以获得该值11.这是否意味着*可以在没有指针的情况下使用此符号(只要我们知道地址)?
为什么下面的代码可以编译成功?
第二个语句int a = 2只是在范围内定义int a = 2,为什么它可以成功编译?
class Test {
int a = 1; // variable a,
{
int a = 2; //duplicate variable
}
}
public class Main {
public static void main(String[] args) {
System.out.println(new Test().a);
}
}
Run Code Online (Sandbox Code Playgroud)